Reputation: 822
I have a (date time) stored in database in this format 2011-10-12 02:01:24
when retrieve this date i want to extract that date so i can show the day or month without the other date value
Upvotes: 1
Views: 7795
Reputation: 822
I solve this with this code:
in my view
<?php
$date_of_post = $r->date_nw;
$date = $date_of_post; // 6 october 2011 2:28 pm
$stamp = strtotime($date); // outputs 1307708880
?>
<?php echo date("d", $stamp); ?> // it prints out the day only
<?php echo date("M", $stamp); ?> // it prints out the Month only like (Oct)
Upvotes: 1
Reputation: 5668
You can use date & time functions of MySQL or PHP functions like strtotime().
For instance, with strtotime()
:
$timestamp = strtotime('2011-10-12 02:01:24');
echo 'The month is '.date('F', $timestamp).' and the day number is '.date('d', $timestamp);
Will outputs:
The month is October and the day number is 12
Upvotes: 2