tags:

views:

37

answers:

2

i want to separate date, month, time, hour, min ,sec getting from database, for count down timer, in data base stored date is 2010/10/10: me using this code :

$m=date('m',$row['Date']);
$d=date('d',$row['Date']);

output is month=31 date = 12....

+1  A: 

If you want them separetely, you can use the explode function with list eg:

list($year, $month, $day) = explode('/', $row['Date']);

Also, you can use the strtotime function for getting individual values:

echo 'Day' . date('d', strtotime($row['Date']));
echo 'Month' . date('m', strtotime($row['Date']));
echo 'Year' . date('Y', strtotime($row['Date']));
Sarfraz
I think it should be `list($year, $month, $day)`
Felix Kling
@Felix Kling: Thanks but i was not in what format he was saving the dates in database but as he mentioned, i thought he was saving them all separated by /. Thanks anyways.
Sarfraz
yap in data base - used. me replace it via /.
Aamir
A: 
$d = // Pull your date from the db
$date = new DateTime($d);

$day = $date->format('l'); // Creates day name
$day = $date->format('j')  // Creates date number
$month = $date->format('n'); // Creates month number
$year = $date->format('Y'); // Creates year

..and so forth.

You can find formatting options here, http://php.net/manual/en/function.date.php

duckbox
$date = new DateTime($d); proble here , done by Sarfraz Ahmed methods
Aamir
@aamir Fayyaz, just pull the date record out of your db without formatting as you would with any record, declare it as '$d' or whatever you wish, then create a new DateTime object with that variable and follow suite with the example.
duckbox