In my MySQL server, I have rows that have the date of my created content. Example: 2013-03-17 02:53:47
For now, I am using:
$date = $fetch[thedaterownamegoeshere];
<?php echo $date; ?>
But instead of getting the full content of the date (2013-03-17 02:53:47), I'd like to get only the date – in this example, I wish to have the number "2013-03-17" as the result. How can I do that?
when fetching put the value into the date function provided by PHP e.g.
$format = 'Y-m-d';
$timestr = strtotime($fetch[thedaterownamegoeshere]);
$date = date($format, $timestr);
Make sure your $fetch returns a string like "2013-03-17 02:53:47"
The format can be formatted in your way. Check http://php.net/manual/en/datetime.formats.date.php for a detailed description. the separators can be changed as well to your preferences, for now, I just set it to ':'.
And of course you can do it shorter like this;
$date = date('Y-m-d', $fetch[thedaterownamegoeshere]);
I hope this helped you out
you can use DATE function in mysql and in your example you can use it like
select DATE(thedaterownamegoeshere) from your_table_name
and also check mysql date document
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date
I hope this helped you..
$date = date('Y-m-d', strtotime($fetch[thedaterownamegoeshere]));
</div>