Hi frnds...

When i was inserting data into mysql table, i used NOW()...

It displays as today date and time.. DD-MM-YYYY hh-mm-ss ...

Now, I want to fetch all records from table, which having date as today...i.e DD-MM-YYYY in this formate...

Plz solve this problem...

Thanks in advance..

9 Years
Discussion Span
Last Post by diafol

Hi there,
Just to clarify, when you pull a date from the database and echo it, it appears in the format DD-MM-YYYY hh-mm-ss.
If thats the case and you just want the date part of the string, you can simply use substr() to get the part you want eg:

$date = substr($dateFromDB,0,10);
echo $date;

if you want to use that date for data manipulation you are gonna have to do it a little differently:

$day = substr($dateFromDB,0,2);
$month = substr($dateFromDB,3,2);
$year = substr($dateFromDB,6,4);
$date = new DateTime();
$date = $date->format("d-m-Y");

Good luck, hope this helped.


Hi menster..

Thanks 4 ur quick reply...

Its working good..But , my requirement is like this....

$date='todays date';//example....
$query="select * from tname where date='$date' ";

But when i was inserting, i use this formate (dd-mm-yyyy hh-mm-ss) in one field only....

The out will be display in while loop...


Forget php functions, go straight to mysql: STR_TO_DATE('31/05/2009', '%d/%m/%Y'); this will insert '2009-05-31'


INSERT INTO mytable SET field1 = '{$field1}', mydate = STR_TO_DATE('{$date}', '%d/%m/%Y'), field3 = '{$field3}'

By the way, you can use this with date+time, not just date.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.