SlideShare a Scribd company logo
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
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

More Related Content

PDF
Graph cafe-lightning
PDF
25. composite l2ltouchpad
PDF
Calculator Program in C#.NET
PDF
ASP.net Image Slideshow
PDF
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
PDF
A simple php exercise on date( ) function
PDF
The Art of Transduction
PPT
Php date &amp; time functions
Graph cafe-lightning
25. composite l2ltouchpad
Calculator Program in C#.NET
ASP.net Image Slideshow
PHP built-in functions date( ) and mktime( ) to calculate age from date of birth
A simple php exercise on date( ) function
The Art of Transduction
Php date &amp; time functions

More from Hock Leng PUAH (20)

PDF
Visual basic asp.net programming introduction
PDF
Using iMac Built-in Screen Sharing
PDF
Hosting SWF Flash file
PDF
Integrate jQuery PHP MySQL project to JOOMLA web site
PPTX
Responsive design
PDF
Step by step guide to use mac lion to make hidden folders visible
PPTX
Beautiful web pages
PPT
CSS Basic and Common Errors
PPTX
Connectivity Test for EES Logic Probe Project
PPTX
Logic gate lab intro
PDF
Ohm's law, resistors in series or in parallel
PPTX
Connections Exercises Guide
PPTX
Design to circuit connection
PPTX
NMS Media Services Jobshet 1 to 5 Summary
DOCX
Virtualbox step by step guide
PPTX
Nms chapter 01
PPTX
Pedagogic Innovation to Engage Academically Weaker Students
PPTX
Objective C Primer (with ref to C#)
PPTX
Do While and While Loop
PPTX
C# looping basic
Visual basic asp.net programming introduction
Using iMac Built-in Screen Sharing
Hosting SWF Flash file
Integrate jQuery PHP MySQL project to JOOMLA web site
Responsive design
Step by step guide to use mac lion to make hidden folders visible
Beautiful web pages
CSS Basic and Common Errors
Connectivity Test for EES Logic Probe Project
Logic gate lab intro
Ohm's law, resistors in series or in parallel
Connections Exercises Guide
Design to circuit connection
NMS Media Services Jobshet 1 to 5 Summary
Virtualbox step by step guide
Nms chapter 01
Pedagogic Innovation to Engage Academically Weaker Students
Objective C Primer (with ref to C#)
Do While and While Loop
C# looping basic
Ad

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Cell Types and Its function , kingdom of life
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
PPTX
Pharma ospi slides which help in ospi learning
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Pre independence Education in Inndia.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Cell Structure & Organelles in detailed.
PDF
Computing-Curriculum for Schools in Ghana
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Lesson notes of climatology university.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Complications of Minimal Access Surgery at WLH
Cell Types and Its function , kingdom of life
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study
Pharma ospi slides which help in ospi learning
Supply Chain Operations Speaking Notes -ICLT Program
Sports Quiz easy sports quiz sports quiz
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
STATICS OF THE RIGID BODIES Hibbelers.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
VCE English Exam - Section C Student Revision Booklet
Pre independence Education in Inndia.pdf
01-Introduction-to-Information-Management.pdf
Cell Structure & Organelles in detailed.
Computing-Curriculum for Schools in Ghana
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Ad

PHP built-in function mktime example

  • 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