I am using $date = date(\"D M d, Y G:i\");
.
When I echo $date
, it shows the correct date/time. Now I need this as an string.
I have tr
The date() function already returns a string.
Doing this :
$date = date("D M d, Y G:i");
You'll have the current date in the $date
variable, as a string -- no need for any additional operation.
If you like working with objects you can do this:
$date = new \DateTime('now');
echo $date->format('D M d, Y G:i');
With regards to:
$today = strtotime($date);
Those numbers are the current timestamp (the number of seconds since January 1st 1970). You can use this as a second parameter in the date function to change the date to whatever you want.
$newDate = date("D M d, Y G:i", $timeStamp);
Your $date
variable is a string, there's no need for any conversion.
You can have a look at the documentation: http://ch.php.net/manual/en/function.date.php. The return value of the date()
function is string.
The strange numbers you see when you call strtotime()
is the Unix timestamp which represents the number of seconds elapsed since January 1 1970 00:00:00 UTC.
You're already getting a string. $date can be used like any string now.
strtotime()
actually gives you the number of seconds in time like unix
$date = 'Today is '.date("D M d, Y G:i", time());
echo $date;