Web Analytics Made Easy -
StatCounter datetime into 12-hour clock - CodingForum

Announcement

Collapse
No announcement yet.

datetime into 12-hour clock

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • datetime into 12-hour clock

    hello, im using the datetime NOW() function to insert the time into my databases, but it puts it in a strange format, it outputs
    2011-08-25 02:09:29
    when it would be a lot better if it outputted
    8/25/11 7:00 PM
    How would I do that? this is my code:
    Code:
    mysql_query("INSERT into completed (username, name, rate, time) VALUES ('$snuid', '$campname', '$points', NOW())");
    and if the only way to do that is to output it into separate columns, what would i put in the values?
    Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

  • #2
    Take a look at date_format()

    Comment


    • #3
      ok i looked, how do i implement that? '%c %e %y %r'
      Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

      Comment


      • #4
        Yep, just add the slashes etc wherever you want them

        Comment


        • #5
          i know that, but how would i put it in my code?
          Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

          Comment


          • #6
            If you have datetime in the mysql field, that's the only format you can use in that field.
            You can only format it on the select query, which is shown on the link I gave

            SELECT DATE_FORMAT('time','%c %e %y %r') FROM blah

            Comment


            • #7
              Code:
              <?
              				$get_name = mysql_query("SELECT DATE_FORMAT('time','%c/%e/%y %r') `username`, `name`, `rate` FROM `completed` WHERE username='$usr'");
               while($namerow = mysql_fetch_array($get_name)) {
              	$date = $namerow["time"];
                	$username = $namerow["username"];
                	$offername = $namerow["name"];
              	$amount = $namerow["rate"];
              ?>
              doesnt work, sorry im really confused idk where to put anything
              Last edited by markman641; Aug 25, 2011, 01:41 AM.
              Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

              Comment


              • #8
                PHP Code:
                $get_name mysql_query("SELECT DATE_FORMAT('time','%c/%e/%y %r') as time, `username`, `name`, `rate` FROM `completed` WHERE username='$usr'"); 
                Showing the error helps, instead of 'doesn't work'.

                You missed a comma, and I thought I'd make it a bit easier to follow by adding the 'as time' in too. That should work now.

                Comment


                • #9
                  its just showing blank. do i have to change the way its inputted and/or my database? i have the string set as datetime?
                  Last edited by markman641; Aug 25, 2011, 01:54 AM.
                  Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

                  Comment


                  • #10


                    PHP Code:
                    $datetime '2011-08-25 02:09:29 ';

                    echo 
                    date'n/j/y, g:i A'strtotime$datetime ) ); // 8/25/11 2:09 AM 
                    ZCE

                    Comment


                    • #11
                      now where would i put that? the insert page or the result page? where on there?
                      Last edited by markman641; Aug 25, 2011, 05:23 PM.
                      Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

                      Comment


                      • #12
                        got it to work. ended up doing:

                        Code:
                        <?
                        				$get_name = mysql_query("SELECT `time`, `username`, `name`, `rate` FROM `completed` WHERE username='$usr'");
                         while($namerow = mysql_fetch_array($get_name)) {
                          	$username = $namerow["username"];
                          	$offername = $namerow["name"];
                        	$amount = $namerow["rate"];
                        	$datetime = $namerow["time"];
                        
                        
                        
                        ?>
                        
                        
                        <tr>
                        <td><?=$offername?></td>
                        <td><?=$amount?></td>
                        <td><? echo date( 'n/j/y, g:i A', strtotime( $datetime ) ); ?></td>
                        </tr>
                        <? }?>
                        Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

                        Comment


                        • #13
                          it seems like the times are off by 4 hours, how do i fix that?
                          Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

                          Comment


                          • #14
                            Hi,

                            try this,
                            <?php

                            $mytime = date("m/d/Y h:i:s",time());

                            mysql_query("INSERT into completed (username, name, rate, time) VALUES ('$snuid', '$campname', '$points', '$mytime')");

                            ?>

                            Originally posted by markman641 View Post
                            hello, im using the datetime NOW() function to insert the time into my databases, but it puts it in a strange format, it outputs when it would be a lot better if it outputted

                            How would I do that? this is my code:
                            Code:
                            mysql_query("INSERT into completed (username, name, rate, time) VALUES ('$snuid', '$campname', '$points', NOW())");
                            and if the only way to do that is to output it into separate columns, what would i put in the values?
                            Smart Web Hub
                            Web Hosting @ just Rs 250/year
                            Get your website at just Rs 6000
                            SEO Services at just Rs 3000 / month

                            Comment


                            • #15
                              not what i was asking at all, its just that the hours are off
                              Ever want to see inside of a rave? Check out RedRoll and join our community of EDM lovers and rave fanatics.

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎