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 tried string($date)
; but nothing happens here. And
$today = strtotime($date);
here I get weird numbers..
I need a string so I can put $today
in a message.
What is the correct method for this?
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.
Answer: Use the PHP date() Function You can simply use the PHP date() function to get the current data and time in various format, for example, date('d-m-y h:i:s') , date('d/m/y H:i:s') , and so on.
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With