SlideShare a Scribd company logo
1 of 11
Date & Time in PHP
By Programmer Blog – http://programmerblog.net
Date & Time – Unix Timestamp
By Programmer Blog – http://programmerblog.net/
 The date/time functions allow you to extract and format the date and time on the server.
 Note: These functions depend on the locale settings of the server!
 Suppose you were tasked with calculating the difference in days between two points in time, but the dates
were provided in the formats July 4, 2005 3:45pm and 7th of December, 2005 18:17 What you would need
is a standard format, some sort of agreement regarding how all dates and times will be presented.
 Preferably, the information would be provided in some sort of numerical format, 20050704154500 and
20051207181700, for example. Date and time values formatted in such a manner are commonly referred to
as timestamps.
 The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch
on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular
date and the Unix Epoch.
 This is very useful to computer systems for tracking and sorting dated information in dynamic and
distributed applications both online and client side.
Date & Time – Unix Timestamp
By Programmer Blog – http://programmerblog.net/
The Unix timestamp is widely used in PHP. It is the amount of seconds between January 1st 1970 00:00:00
(Unix Epoch) and the present time, to the closest second.
The Unix epoch is the time 00:00:00 UTC on 1 January 1970 (or 1970-01-01T00:00:00Z ISO 8601).
Even this improved situation has its problems. For instance, this proposed solution still doesn’t resolve
challenges presented by time zones, matters pertinent to time adjustment due to daylight savings, or cultural date
format variances.
January 19, 2038 Unix Time Stamp will cease to work due to a 32-bit overflow. Before this moment millions of
applications will need to either adopt a new convention for time stamps or be migrated to 64-bit systems which
will buy the time stamp a "bit" more time.
Date & Time PHP
By Programmer Blog – http://programmerblog.net/
 Even the simplest of PHP applications often involve at least a few of PHP’s date- and time-related functions
 checkdate()
 boolean checkdate (int month, int day, int year)
 the checkdate() function accomplishes the task of validating dates quite nicely, returning TRUE if the date
specified by month, day, and year is valid, and FALSE otherwise.
 echo checkdate(4, 31, 2005);
 // returns false
 echo checkdate(03, 29, 2004);
 // returns true, because 2004 was a leap yearf
 echo checkdate(03, 29, 2005);
 // returns false, because 2005 is not a leap year
 date()
 string date (string format [, int timestamp])
 The date() function returns a string representation of the present time and/or date formatted
 according to the instructions specified by format.
Date & Time
By Programmer Blog – http://programmerblog.net/
The date() Function’s Format Parameters
 a Lowercase ante meridiem and post meridiem am or pm
 A Uppercase ante meridiem and post meridiem AM or PM
 d Day of the month, with leading zero 01 to 31
 D Three-letter text representation of day Mon through Sun
 F Complete text representation of month January through December
 h 12-hour format of hour, with zeros 01 through 24
 H 24-hour format, with zeros 01 through 24
 i Minutes, with zeros 01 through 60
 m Numeric representation of month, with zeros 01 through 12
 M Three-letter text representation of month Jan through Dec
 s Seconds, with zeros 01 through 59
 U Seconds since Unix epoch 1114646885
 Y Four-digit representation of year
Date & Time
By Programmer Blog – http://programmerblog.net/
 echo "Today is ".date("F d, Y");
 echo "Today is ".date("l");
 $weekday = date("l");
 $daynumber = date("dS");
 $monthyear = date("F Y");
 printf("Today is %s the %s day of %s", $weekday, $daynumber, $monthyear);
Working with Time
By Programmer Blog – http://programmerblog.net/
 echo date("m-d-Y");
 Working with Time
 The date() function can also produce time-related values. Let’s run through a few examples,
 starting with simply outputting the present time:
 echo "The time is ".date("h:i:s");
 echo "The time is ".date("h:i:sa");
 getdate()
 array getdate ([int timestamp]) // getdate(1114284300)
 gettimeofday()
 mixed gettimeofday ([bool return_float])
Working with Time
By Programmer Blog – http://programmerblog.net
 mktime()
 int mktime ([int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]])
 The mktime() function is useful for producing a timestamp, in seconds, between the Unix
 epoch and a given date and time.
 echo mktime(20,50,00,4,27,2005);
 $now = mktime();
 $taxday = mktime(0,0,0,4,15,2006);
 // Difference in seconds
 $difference = $taxday - $now;
Date & Time
By Programmer Blog – http://programmerblog.net/
 time()
 int time()
 The time() function is useful for retrieving the present Unix timestamp.
 echo date("F d, Y h:i:s", 1114284300);
 setlocale()
 It’s possible to specify a locale for a particular classification of data. Six different categories are supported:
 strftime()
 string strftime (string format [, int timestamp])
 The strftime() function formats a date and time according to the localization setting as specified by
setlocale().
 %B Complete month name January, February
 %d Numerical day of month, with leading zero 01, 15, 26
 %m Numerical month, with leading zero 01 through 12
 %Y Numerical year, with century 2005
Date & Time
By Programmer Blog – http://programmerblog.net
 getlastmod()
 int getlastmod()
 The getlastmod() function returns the value of the page’s Last-Modified header, or FALSE in the case of an
error.
 $lastmod = date("F d, Y h:i:sa", getlastmod());
 echo "Page last modified on $lastmod";
Date & Time
By Programmer Blog – http://programmerblog.net
Thanks for viewing this slide on php date and time functions
Please visit our blog for more detailed tutorials:
http://programmerblog.net/
Subscribe to our newsletter to stay updated on upcoming articles and tutorials

More Related Content

Similar to Php date & time functions

How to work with dates and times in swift 3
How to work with dates and times in swift 3How to work with dates and times in swift 3
How to work with dates and times in swift 3allanh0526
 
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.pdfankit11134
 
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.pdfjaipur2
 
SessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTimeSessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTimeHellen Gakuruh
 
Date and time manipulation
Date and time manipulationDate and time manipulation
Date and time manipulationShahjahan Samoon
 
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 8Fulvio Corno
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8Serhii Kartashov
 
Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v22x026
 
C# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slidesC# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slidesSami Mut
 
13 -times_and_dates
13  -times_and_dates13  -times_and_dates
13 -times_and_datesHector Garzo
 
Data Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing ItData Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing Itkanaugust
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3Kenji HASUNUMA
 

Similar to Php date & time functions (20)

jkfdlsajfklafj
jkfdlsajfklafjjkfdlsajfklafj
jkfdlsajfklafj
 
17 ruby date time
17 ruby date time17 ruby date time
17 ruby date time
 
How to work with dates and times in swift 3
How to work with dates and times in swift 3How to work with dates and times in swift 3
How to work with dates and times in swift 3
 
Python time
Python timePython time
Python time
 
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
 
SessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTimeSessionSeven_WorkingWithDatesandTime
SessionSeven_WorkingWithDatesandTime
 
Date and time manipulation
Date and time manipulationDate and time manipulation
Date and time manipulation
 
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
 
JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8JSR 310. New Date API in Java 8
JSR 310. New Date API in Java 8
 
Computer programming 2 Lesson 14
Computer programming 2  Lesson 14Computer programming 2  Lesson 14
Computer programming 2 Lesson 14
 
Epoch Time
Epoch TimeEpoch Time
Epoch Time
 
15. DateTime API.ppt
15. DateTime API.ppt15. DateTime API.ppt
15. DateTime API.ppt
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
Date object.pptx date and object v
Date object.pptx date and object        vDate object.pptx date and object        v
Date object.pptx date and object v
 
C# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slidesC# Tutorial MSM_Murach chapter-09-slides
C# Tutorial MSM_Murach chapter-09-slides
 
13 -times_and_dates
13  -times_and_dates13  -times_and_dates
13 -times_and_dates
 
Data Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing ItData Wrangling: Working with Date / Time Data and Visualizing It
Data Wrangling: Working with Date / Time Data and Visualizing It
 
Y2 k38.
Y2 k38.Y2 k38.
Y2 k38.
 
Introduction to Date and Time API 3
Introduction to Date and Time API 3Introduction to Date and Time API 3
Introduction to Date and Time API 3
 

Recently uploaded

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 

Recently uploaded (20)

What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 

Php date & time functions

  • 1. Date & Time in PHP By Programmer Blog – http://programmerblog.net
  • 2. Date & Time – Unix Timestamp By Programmer Blog – http://programmerblog.net/  The date/time functions allow you to extract and format the date and time on the server.  Note: These functions depend on the locale settings of the server!  Suppose you were tasked with calculating the difference in days between two points in time, but the dates were provided in the formats July 4, 2005 3:45pm and 7th of December, 2005 18:17 What you would need is a standard format, some sort of agreement regarding how all dates and times will be presented.  Preferably, the information would be provided in some sort of numerical format, 20050704154500 and 20051207181700, for example. Date and time values formatted in such a manner are commonly referred to as timestamps.  The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch.  This is very useful to computer systems for tracking and sorting dated information in dynamic and distributed applications both online and client side.
  • 3. Date & Time – Unix Timestamp By Programmer Blog – http://programmerblog.net/ The Unix timestamp is widely used in PHP. It is the amount of seconds between January 1st 1970 00:00:00 (Unix Epoch) and the present time, to the closest second. The Unix epoch is the time 00:00:00 UTC on 1 January 1970 (or 1970-01-01T00:00:00Z ISO 8601). Even this improved situation has its problems. For instance, this proposed solution still doesn’t resolve challenges presented by time zones, matters pertinent to time adjustment due to daylight savings, or cultural date format variances. January 19, 2038 Unix Time Stamp will cease to work due to a 32-bit overflow. Before this moment millions of applications will need to either adopt a new convention for time stamps or be migrated to 64-bit systems which will buy the time stamp a "bit" more time.
  • 4. Date & Time PHP By Programmer Blog – http://programmerblog.net/  Even the simplest of PHP applications often involve at least a few of PHP’s date- and time-related functions  checkdate()  boolean checkdate (int month, int day, int year)  the checkdate() function accomplishes the task of validating dates quite nicely, returning TRUE if the date specified by month, day, and year is valid, and FALSE otherwise.  echo checkdate(4, 31, 2005);  // returns false  echo checkdate(03, 29, 2004);  // returns true, because 2004 was a leap yearf  echo checkdate(03, 29, 2005);  // returns false, because 2005 is not a leap year  date()  string date (string format [, int timestamp])  The date() function returns a string representation of the present time and/or date formatted  according to the instructions specified by format.
  • 5. Date & Time By Programmer Blog – http://programmerblog.net/ The date() Function’s Format Parameters  a Lowercase ante meridiem and post meridiem am or pm  A Uppercase ante meridiem and post meridiem AM or PM  d Day of the month, with leading zero 01 to 31  D Three-letter text representation of day Mon through Sun  F Complete text representation of month January through December  h 12-hour format of hour, with zeros 01 through 24  H 24-hour format, with zeros 01 through 24  i Minutes, with zeros 01 through 60  m Numeric representation of month, with zeros 01 through 12  M Three-letter text representation of month Jan through Dec  s Seconds, with zeros 01 through 59  U Seconds since Unix epoch 1114646885  Y Four-digit representation of year
  • 6. Date & Time By Programmer Blog – http://programmerblog.net/  echo "Today is ".date("F d, Y");  echo "Today is ".date("l");  $weekday = date("l");  $daynumber = date("dS");  $monthyear = date("F Y");  printf("Today is %s the %s day of %s", $weekday, $daynumber, $monthyear);
  • 7. Working with Time By Programmer Blog – http://programmerblog.net/  echo date("m-d-Y");  Working with Time  The date() function can also produce time-related values. Let’s run through a few examples,  starting with simply outputting the present time:  echo "The time is ".date("h:i:s");  echo "The time is ".date("h:i:sa");  getdate()  array getdate ([int timestamp]) // getdate(1114284300)  gettimeofday()  mixed gettimeofday ([bool return_float])
  • 8. Working with Time By Programmer Blog – http://programmerblog.net  mktime()  int mktime ([int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]])  The mktime() function is useful for producing a timestamp, in seconds, between the Unix  epoch and a given date and time.  echo mktime(20,50,00,4,27,2005);  $now = mktime();  $taxday = mktime(0,0,0,4,15,2006);  // Difference in seconds  $difference = $taxday - $now;
  • 9. Date & Time By Programmer Blog – http://programmerblog.net/  time()  int time()  The time() function is useful for retrieving the present Unix timestamp.  echo date("F d, Y h:i:s", 1114284300);  setlocale()  It’s possible to specify a locale for a particular classification of data. Six different categories are supported:  strftime()  string strftime (string format [, int timestamp])  The strftime() function formats a date and time according to the localization setting as specified by setlocale().  %B Complete month name January, February  %d Numerical day of month, with leading zero 01, 15, 26  %m Numerical month, with leading zero 01 through 12  %Y Numerical year, with century 2005
  • 10. Date & Time By Programmer Blog – http://programmerblog.net  getlastmod()  int getlastmod()  The getlastmod() function returns the value of the page’s Last-Modified header, or FALSE in the case of an error.  $lastmod = date("F d, Y h:i:sa", getlastmod());  echo "Page last modified on $lastmod";
  • 11. Date & Time By Programmer Blog – http://programmerblog.net Thanks for viewing this slide on php date and time functions Please visit our blog for more detailed tutorials: http://programmerblog.net/ Subscribe to our newsletter to stay updated on upcoming articles and tutorials