Hi all,
I need some help with using dates in php. My page is getting the date caled 'Due Date' and printing it in a table. See php code:
echo "<tr><td>" . date("M d Y",strtotime($row['DueDate'])) . "</td>";
I want to set variables to the month, date and year. Does anybody know how to do this? I'm new to php and so any help here is much needed and will be much appreciated!
Thank you!
Need help with Dates in PHP
Moderator: General Moderators
-
ciaranholland
- Forum Newbie
- Posts: 6
- Joined: Sat Feb 20, 2010 6:50 pm
Re: Need help with Dates in PHP
The method I use is
list, explode
Or you could make three separate calls to date().
Code: Select all
list($year, $month, $day) = explode("-", date("Y-m-d", $whatever));Or you could make three separate calls to date().
Re: Need help with Dates in PHP
Using three separate calls to $date ($date is passed as $val in this case), use substr() to get the parts:.
I did this to get day, month and year from a date/time datestamp. You can see what I did here:
I did this to get day, month and year from a date/time datestamp. You can see what I did here:
Code: Select all
// Date from mysql datestamp
function get_date($val){
$year = substr($val, 0, 4);
$month = substr($val, 5, 2);
$day = substr($val, 8, 2);
$date = date('D d M Y', mktime(0, 0, 0, $month, $day, $year));
return $date;
}
// Time from mysql datestamp
function get_time($val){
$hh=substr($val,11,2);
$mm=substr($val,14,2);
$time = date('H:i', mktime($hh, $mm));
return $time;
}