Hi everyone,
I’d like to create a variable : “$myDate” of date type with a value attached: “2001-01-31” which is 31th January 2001.
Problem is, I dont know how to do it
Can anyone, please, show me how to assign a date to a date variable in PHP?
Thanks
Have a look at the date()
function - http://php.net/manual/en/function.date.php and see how you get on…
2 Likes
As far as I know PHP does not have a date variable, maybe you mean a string?
http://php.net/manual/en/function.date.php
<?php
echo '<h3> Seconds is since Unix Epoch (January 1 1970 00:00:00 GMT) </h3>';
$time = time();
$day = date('Y-m-d \w\a\s l', $time);
echo '<br>$time = ' .$time;
echo '<br>$day =' .$day;
echo '<br><br>';
$date = '31st January 2001';
$time = strtotime( $date );
$day = date('Y-m-d \w\a\s l', $time);
echo '<br>date = ' .$date;
echo '<br>$time = ' .$time;
echo '<br>$day =' .$day;
echo '<br><br>';
$date = 'January 31st 2001';
$time = strtotime( $date );
$day = date('Y-m-d \w\a\s l', $time);
echo '<br>date = ' .$date;
echo '<br>$time = ' .$time;
echo '<br>$day =' .$day;
echo '<br><br>';
?>
Output:
3 Likes
Thank you gandalf.
I’ll try to assimilate it.
1 Like
Thanks a lot John !
1 Like
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.