SlideShare une entreprise Scribd logo
1  sur  2
Télécharger pour lire hors ligne
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

Contenu connexe

Similaire à PHP built-in function mktime example

Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
ankit11134
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
jaipur2
 
Hi,I have implemented increment() method. Please find the below up.pdf
Hi,I have implemented increment() method. Please find the below up.pdfHi,I have implemented increment() method. Please find the below up.pdf
Hi,I have implemented increment() method. Please find the below up.pdf
Ankitchhabra28
 

Similaire à PHP built-in function mktime example (20)

Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdfPlease I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
 
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdfC++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
 
Cmis 102 hands on/tutorialoutlet
Cmis 102 hands on/tutorialoutletCmis 102 hands on/tutorialoutlet
Cmis 102 hands on/tutorialoutlet
 
Java exercise1
Java exercise1Java exercise1
Java exercise1
 
第5回 様々なファイル形式の読み込みとデータの書き出し(解答付き)
第5回 様々なファイル形式の読み込みとデータの書き出し(解答付き)第5回 様々なファイル形式の読み込みとデータの書き出し(解答付き)
第5回 様々なファイル形式の読み込みとデータの書き出し(解答付き)
 
The War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS RegimeThe War is Over, and JavaScript has won: Living Under the JS Regime
The War is Over, and JavaScript has won: Living Under the JS Regime
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
Python Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime modulePython Programming Essentials - M23 - datetime module
Python Programming Essentials - M23 - datetime module
 
Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8
 
C- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutionsC- Programming Assignment practice set 2 solutions
C- Programming Assignment practice set 2 solutions
 
Go Says WAT?
Go Says WAT?Go Says WAT?
Go Says WAT?
 
date2.docx
date2.docxdate2.docx
date2.docx
 
2. data types, variables and operators
2. data types, variables and operators2. data types, variables and operators
2. data types, variables and operators
 
17 ruby date time
17 ruby date time17 ruby date time
17 ruby date time
 
Om nom nom nom
Om nom nom nomOm nom nom nom
Om nom nom nom
 
jkfdlsajfklafj
jkfdlsajfklafjjkfdlsajfklafj
jkfdlsajfklafj
 
doc
docdoc
doc
 
Hi,I have implemented increment() method. Please find the below up.pdf
Hi,I have implemented increment() method. Please find the below up.pdfHi,I have implemented increment() method. Please find the below up.pdf
Hi,I have implemented increment() method. Please find the below up.pdf
 
From the proposal to ECMAScript, step by step
From the proposal to ECMAScript, step by stepFrom the proposal to ECMAScript, step by step
From the proposal to ECMAScript, step by step
 
C語言函式
C語言函式C語言函式
C語言函式
 

Plus de Hock Leng PUAH

CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
Hock Leng PUAH
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
Hock Leng PUAH
 

Plus de Hock Leng PUAH (20)

Visual basic asp.net programming introduction
Visual basic asp.net programming introductionVisual basic asp.net programming introduction
Visual basic asp.net programming introduction
 
Using iMac Built-in Screen Sharing
Using iMac Built-in Screen SharingUsing iMac Built-in Screen Sharing
Using iMac Built-in Screen Sharing
 
Hosting SWF Flash file
Hosting SWF Flash fileHosting SWF Flash file
Hosting SWF Flash file
 
A simple php exercise on date( ) function
A simple php exercise on date( ) functionA simple php exercise on date( ) function
A simple php exercise on date( ) function
 
Integrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web siteIntegrate jQuery PHP MySQL project to JOOMLA web site
Integrate jQuery PHP MySQL project to JOOMLA web site
 
Responsive design
Responsive designResponsive design
Responsive design
 
Step by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visibleStep by step guide to use mac lion to make hidden folders visible
Step by step guide to use mac lion to make hidden folders visible
 
Beautiful web pages
Beautiful web pagesBeautiful web pages
Beautiful web pages
 
CSS Basic and Common Errors
CSS Basic and Common ErrorsCSS Basic and Common Errors
CSS Basic and Common Errors
 
Connectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe ProjectConnectivity Test for EES Logic Probe Project
Connectivity Test for EES Logic Probe Project
 
Logic gate lab intro
Logic gate lab introLogic gate lab intro
Logic gate lab intro
 
Ohm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallelOhm's law, resistors in series or in parallel
Ohm's law, resistors in series or in parallel
 
Connections Exercises Guide
Connections Exercises GuideConnections Exercises Guide
Connections Exercises Guide
 
Design to circuit connection
Design to circuit connectionDesign to circuit connection
Design to circuit connection
 
NMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 SummaryNMS Media Services Jobshet 1 to 5 Summary
NMS Media Services Jobshet 1 to 5 Summary
 
Virtualbox step by step guide
Virtualbox step by step guideVirtualbox step by step guide
Virtualbox step by step guide
 
Nms chapter 01
Nms chapter 01Nms chapter 01
Nms chapter 01
 
Pedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker StudentsPedagogic Innovation to Engage Academically Weaker Students
Pedagogic Innovation to Engage Academically Weaker Students
 
Objective C Primer (with ref to C#)
Objective C  Primer (with ref to C#)Objective C  Primer (with ref to C#)
Objective C Primer (with ref to C#)
 
Do While and While Loop
Do While and While LoopDo While and While Loop
Do While and While Loop
 

Dernier

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
SoniaTolstoy
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Dernier (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

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