-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,021
  • 5
  • 24
  • 51

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
  • 129,293
  • 10
  • 87
  • 97
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
  • 531
  • 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")