www.webdeveloper.com
Results 1 to 2 of 2

Thread: fetch current date record of dd/mm/yyyy format in php mysql

  1. #1
    Join Date
    Jan 2014
    Posts
    3

    Question fetch current date record of dd/mm/yyyy format in php mysql

    Hello experts,

    I am stuck with an query. Actually i want to fetch current date records from my database and the below code probably fetches all my current date records. But it fetches in d/m/y (26/01/14) format but i need in dd/mm/yyyy (26/01/2014) .
    Below is the code which gives output as d/m/y format:

    PHP Code:
    <?php
    ini_set
    "display_errors"0);
    $con=mysqli_connect("localhost","root","","test");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo 
    "Failed to connect to MySQL: " mysqli_connect_error();
      }
    $today date('d-m-y');
    $result mysqli_query($con,"SELECT * FROM Persons WHERE DATE(startdate) = '$today'");

    echo 
    "<table border='1'>
    <tr>
    <th>id</th>
    <th>name</th>
    <th>Startdate</th>
    <th>Details</th>

    </tr>"
    ;

    while(
    $row mysqli_fetch_array($result))
      {
      echo 
    "<tr>";
    echo 
    "<td>" $row['id'] . "</td>";
      echo 
    "<td>" $row['name'] . "</td>";
      echo 
    "<td>" $row['startdate'] . "</td>";
       echo 
    "<td>" $row['details'] . "</td>";
      echo 
    "</tr>";
      }
    echo 
    "</table>";

    mysqli_close($con);
    ?>
    I tried with the above code and also tried to change the date format i.e :
    $today = date('d-m-y');
    to $today = date('dd-mm-yyyy');

    I am not understanding what i am missing. Just need some help in this. Any help is appreciated.

  2. #2
    Join Date
    Jul 2013
    Posts
    350
    Have you tried displaying the result of your DATE function from your query statement to see what that value looks like? AFAIK, dates from a MySQL db are in the form yyyy-mm-dd which you can alter by using the DATE_FORMAT (?) function, not DATE. I think in your case you can alter either the query's function or the date functions format to make them align

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles