-4

I am using mssql db with php. Which PHP function can return the current datetime. (i.e.) I want the current date and time to be saved in the following format say for example,

2016-07-04 11:10:05.000

Thanks!

Deepak Keynes
  • 2,291
  • 5
  • 27
  • 56

3 Answers3

5

Use date->format http://php.net/manual/it/function.date.php

$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s.u');
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
1

With "date" you can format the output and with "time" you get the current unix time.

Example

echo date("Y-m-d H:i:s.u", time());

Documentation: http://php.net/manual/it/function.date.php

Fabio Widmer
  • 529
  • 1
  • 7
  • 19
1

12-hour format

date("Y-m-d h:i:s.u")

24-hour format

date("Y-m-d H:i:s.u")