1//Get current date time in PHP
2
3// Simply:
4$date = date('Y-m-d H:i:s');
5
6// Or:
7$date = date('Y/m/d H:i:s');
8
9// This would return the date in the following formats respectively:
10$date = '2012-03-06 17:33:07';
11// Or
12$date = '2012/03/06 17:33:07';
13
14/**
15 * This time is based on the default server time zone.
16 * If you want the date in a different time zone,
17 * say if you come from Nairobi, Kenya like I do, you can set
18 * the time zone to Nairobi as shown below.
19 */
20
21date_default_timezone_set('Africa/Nairobi');
22
23// Then call the date functions
24$date = date('Y-m-d H:i:s');
25// Or
26$date = date('Y/m/d H:i:s');
27
28// date_default_timezone_set() function is however
29// supported by PHP version 5.1.0 or above.
30
1<?php
2/* Unix Timestamp */
3$timestamp = time();
4echo $timestamp . "<br>";
5echo date("d/m/Y", $timestamp);
6?>
1Return the current time as a Unix timestamp, then format it to a date:
2<?php
3/* Unix Timestamp */
4$timestamp = time();
5echo $timestamp . "<br>";
6echo date("d/m/Y", $timestamp);
7?>
1
2<?php
3$nextWeek = time() + (7 * 24 * 60 * 60);
4 // 7 Tage; 24 Stunden; 60 Minuten; 60 Sekunden
5echo 'Jetzt: '. date('Y-m-d') ."\n";
6echo 'Naechste Woche: '. date('Y-m-d', $nextWeek) ."\n";
7// oder strtotime() verwenden:
8echo 'Naechste Woche: '. date('Y-m-d', strtotime('+1 week')) ."\n";
9?>
10
11