Reputation: 2800
This my code to generate current date.
$now= Time();
$dt=date("d", strtotime($now));
echo $dt;
It outputs 01
as d-m-Y
outputs 01-01-1970
instead of current date.
$dt
is string and $now
is integer type. What should I do to get correct date and get it as integer type.
Upvotes: 0
Views: 131
Reputation: 8369
You don't need to convert time()
to strtotime()
. strtotime()
accepts date as string. time()
will return the current time in integer only.
Try with
$date = date('d', time());
Upvotes: 1
Reputation: 12039
You can try this if you want to get current date
$dt=date("d-m-Y", strtotime('today')); //dd-mm-yyyy
echo $dt;
OR
$current_date_in_int = Time();
$current_date_in_string = date('d-m-Y', $current_date_in_int); //dd-mm-yyyy
echo $current_date_in_string;
Upvotes: 0