-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path09_dates.php
More file actions
29 lines (21 loc) · 768 Bytes
/
09_dates.php
File metadata and controls
29 lines (21 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
// Print current date
echo date('Y-m-d H:i:s') . '<br>';
// Print yesterday
echo date('Y-m-d H:i:s', time() - 60 * 60 * 24) . '<br>';
// Different format: https://www.php.net/manual/en/function.date.php
echo date('F j Y, H:i:s') . '<br>';
// Print current timestamp
echo Time() . '<br>';
// Parse date: https://www.php.net/manual/en/function.date-parse.php
$parsedDate = 'december 4 2021 12:45:35';
$parsedDate = date_parse('2021-10-12 09:00:00:');
echo '<pre>';
var_dump($parsedDate);
echo '</pre>';
// Parse date from format: https://www.php.net/manual/en/function.date-parse-from-format.php
$parsedDate = 'december 4 2021 12:45:35';
$parsedDate = date_parse_from_format('F j Y H:i:s', $dateString);
echo '<pre>';
var_dump($parsedDate);
echo '</pre>';