0

I would like to get timestamp for current date and current time. I has searching for it today, but no luck, I got confused. I'm very basic in PHP btw :( The timestamp are correct, but I get that notice.

<?php
$current_time_and_date = mktime(date("h"), date("i"), date("sa"), date("m"), date("d"), date("Y"));
echo $current_time_and_date;

Result:

Notice: A non well formed numeric value encountered in C:\xampp\htdocs\index.php on line 2

1551814433

Community
  • 1
  • 1
  • Please check this : https://stackoverflow.com/questions/20574465/date-method-a-non-well-formed-numeric-value-encountered-does-not-want-to-fo – Mayank Dudakiya Mar 06 '19 at 07:45
  • This will give you current timestamp `` – Mayank Dudakiya Mar 06 '19 at 07:47
  • You need to use `date('H')` instead of `date('h')` and `date('s')` instead of `date('sa')` to fix your code but you should really just use `time()` – Nick Mar 06 '19 at 07:51
  • Forget about `mktime()` and the other awkward date & time function. Use the [`DateTime`](http://php.net/manual/en/class.datetime.php) class. It is easier to use and it can also handle the timezone (handling the timezone using the old date & time functions is painful and not always possible). – axiac Mar 06 '19 at 07:54
  • Yeah It's look awkward in mktime XD I got new knowledge today, Thank you guys! –  Mar 06 '19 at 07:59

2 Answers2

0

simply use time() function

<?php
echo time();
?>
u_mulder
  • 54,101
  • 5
  • 48
  • 64
devil
  • 24
  • 4
0

Please check http://php.net/manual/fr/function.date.php

Exemple #4 echo date("Y-m-d H:i:s");