Currently I have a datetime like this:
2012-07-24 11:52:01
Now i want to show only date like 2012-07-24
.
Can anyone give any php function? Thanks.
Currently I have a datetime like this:
2012-07-24 11:52:01
Now i want to show only date like 2012-07-24
.
Can anyone give any php function? Thanks.
just follow the following procedure
date("Y-m-d",strtotime("2012-07-24 11:52:01"));
in above code strtotime() returns value of date in seconds and "Y-m-d" transfers it in Y-M-D format of date as date() method is used.
Go ahead and use PHP's DateTime class. I was reluctant to move away from functions to classes, but it's really not that hard. Just pass the date string into the class object and then use the format method to output the date string in the way you want.
http://php.net/manual/en/class.datetime.php
$dt = new DateTime('2012-07-24 11:52:01');
echo $dt->format('Y-m-d');
$date = "2012-07-24 11:52:01";
$pieces = explode(" ", $date);
echo $pieces[0];
Check php manual for more reference: http://php.net/manual/en/function.date.php
Little research please
$today = date("Y-m-d ");