1 <?php
2 // Part 1:
3 // Use date( ) function to create the value for
4 // $today_year (Current year in 4 digits)
5 // $today_month (Current month)
6 // $today_day (Current day)
7
8 $today_year = date('Y'); // Eg 2014, 2015
9 $today_month = date('m'); // Eg 01, 02, 03 ..., 12
10 $today_day = date('d'); // Eg 01, ...,21...., 31
11
12 // Part 2:
13 // Use variables from part 1 and mktime( ) function to create the timestamps for
14 // 2.1 Two days ago from today ($timestamp1)
15 // 2.2 Five months ago from today ($timestamp2)
16 // 2.2 Three years later from today ($timestamp3)
17 // mktime(hr, min, sec, month, day, year)
18
19 $timestamp1 = mktime(0, 0, 0, $today_month, $today_day - 2, $today_year);
20 $timestamp2 = mktime(0, 0, 0, $today_month - 5, $today_day, $today_year);
21 $timestamp3 = mktime(0, 0, 0, $today_month, $today_day, $today_year + 3);
22
23 // Part 3:
24 // Use timestamps created in part 2 and date( ) function to output
25 // 3.1 Date of "Two days ago from today" in dd-mmm-yyyy format
26 // 3.2 Date of "Five months ago from today" in dd-mmmmmm-yyyy format
27 // 3.2 Date of "Three years ago from today" in dd/mm/yy format
28 // Refer to 'PHP Manual' search for date( ) function
29
30 echo 'Two days ago from today is ' . date('d-M-Y', $timestamp1) . '<br>';
31 // Eg Two days ago from today is 01-Feb-2014
32 echo 'Five months ago from today is ' . date('d-F-Y', $timestamp2) . '<br>';
Macintosh HD:Applications:XAMPP:xamppfiles:htdocs:php:dob.php: 1/2