Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    22
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Angry Date format problem in sql saving

    Hy every one i have this two file code one is index.php and second is insert.php

    here is index.php code ,

    <html>
    <body>

    <form action="insert.php" method="post">
    Time <input type="text" name="time" />
    <input type="submit" />
    </form>

    <?php
    $ctime = date('h:i:s A');
    echo "Current time is : " . $ctime ;
    echo "<br>";

    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("time", $con);

    $result = mysql_query("SELECT * FROM time");

    while($row = mysql_fetch_array($result))
    {
    echo $row['time'];
    echo "<br />";
    }

    mysql_close($con);
    ?>


    </body>
    </html>


    here is insert.php code ,

    <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("time", $con);

    $sql="INSERT INTO time (time )
    VALUES
    ('$_POST[time]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";
    echo "<br>";
    echo "<a href='index.php'>Home</a>";

    mysql_close($con)
    ?>


    This code work fine but when it returns me the ouput in this format

    Time (inputbox) submit

    Current time is : 07:25:53 PM

    10:55:00
    10:55:00


    i saved one value with 10:55 AM in my field box and one value with 10:55 PM but no effect what is the problem i want to display the output as like this,

    10:55:00 AM
    10:55:00 PM

    Hope you understand what i want...
    thanks

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,633
    Thanks
    4
    Thanked 148 Times in 139 Posts
    See DATE_FORMAT in the manual. You can add PM/AM options.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •