1. 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
30
31
32
<?php
// Part 1:
// Use date( ) function to create the value for
// $today_year (Current year in 4 digits)
// $today_month (Current month)
// $today_day
(Current day)
$today_year = date('Y');
$today_month = date('m');
$today_day
= date('d');
//
//
//
//
//
//
// Eg 2014, 2015
// Eg 01, 02, 03 ..., 12
// Eg 01, ...,21...., 31
Part 2:
Use variables from part 1 and mktime( ) function to create the timestamps for
2.1 Two days ago from today ($timestamp1)
2.2 Five months ago from today ($timestamp2)
2.2 Three years later from today ($timestamp3)
mktime(hr, min, sec, month, day, year)
$timestamp1 = mktime(0, 0, 0, $today_month,
$timestamp2 = mktime(0, 0, 0, $today_month - 5,
$timestamp3 = mktime(0, 0, 0, $today_month,
//
//
//
//
//
//
$today_day - 2,
$today_day,
$today_day,
$today_year);
$today_year);
$today_year + 3);
Part 3:
Use timestamps created in part 2 and date( ) function to output
3.1 Date of "Two days ago from today" in
dd-mmm-yyyy format
3.2 Date of "Five months ago from today" in dd-mmmmmm-yyyy format
3.2 Date of "Three years ago from today" in dd/mm/yy format
Refer to 'PHP Manual' search for date( ) function
echo 'Two days ago from today is ' .
date('d-M-Y', $timestamp1) . '<br>';
// Eg Two days ago from today is 01-Feb-2014
echo 'Five months ago from today is ' .
date('d-F-Y', $timestamp2) . '<br>';
Macintosh HD:Applications:XAMPP:xamppfiles:htdocs:php:dob.php: 1/2
2. 33
34
35
36
37
// Eg Five months ago from today is 03-September-2013
echo 'Three years later from today is ' . date('d/m/y', $timestamp3) . '<br>';
// Eg Three years later from today is 03/02/17
?>
Macintosh HD:Applications:XAMPP:xamppfiles:htdocs:php:dob.php: 2/2