PHP Syntax Variables Date

 

- Info:

- PHP has only one type of variable, called scalar.

- This tutorial shows possible ways of loading scalar with date and time values.

- This tutorial is based on:

- http://php.net/manual/en/function.date.php

- http://php.net/manual/en/function.strtotime.php

 

- Date To String:

- Date function returns formated string which represents curent date or date given as second argument:

$date = date('d.m.y h:i:s'); //07.02.12 04:15:16

$date = date('D.m.y h:i:s'); //Tue.02.12 04:15:16

$date = date('j.m.y h:i:s'); //7.02.12 04:15:16

$date = date('j.F.y h:i:s'); //7.February.12 04:15:16

$date = date('j.M.y h:i:s'); //7.Feb.12 04:15:16

$date = date('j.n.y h:i:s'); //7.2.12 04:15:16

$date = date('j.n.Y h:i:s'); //7.2.2012 04:15:16

$date = date('j.n.Y g:i:s'); //7.2.2012 4:15:16

- Function strtotime() converts string into Unix timestamp:

$date = date('j-F-Y', strtotime('2007-04-09')); //9-April-2007

 

- Display:

echo ($date);

print ($date);

printf($date);




0 + 0 =