View your Shopping CartFrequently Asked QuestionsEmail Us
Home | About Us | Contact Us
SmartWebby.com provides best web design & web programming services globally
We specialize in Rapid Web Design, ASP.net, ASP and PHP web programmingBest Web Design, Best Web Programming, Global Service Provider - Dependable Professionals to build your website right!

Date Functions in PHP

In this tutorial you will learn about some Date functions in PHP.

  1. Getting the Current Date
  2. Getting Number of days in a month
  3. Check the date format

For Date Formats refer: PHP Date Function Tips

1. Getting the Current Date

The PHP function 'date' is used to display the current date in the specified format as indicated by its arguments as shown in the above example. For more details on date format arguments, click PHP Date Function Tips.

Syntax

date('format options');

Example:

1.date('y m d'); Output: 05 04 23

2. date('Y M D'); Output: 2005 Apr Sat

3.date('Y m d h: s: m'); Output: 2005 04 23 02: 18: 04 (Date and Time)

2. Number of days in a month

The function 'cal_days_in_month' is used to return the number of days in a month. This function takes three arguments one for calendar name, month value and year value respectively.

Syntax

cal_days_in_month( CAL_GREGORIAN, $intMonth, $intYear);

Example:

cal_days_in_month ( CAL_GREGORIAN, 1, 2005); Output: 31

3. Check the date format

The function 'checkdate' is used to check whether the date passed as an argument is a valid date or not. The function returns a boolean value of '1' if the date is a valid date and 'Null' if the date is invalid.

Syntax

checkdate ($intMonth,$date, $intYear);

Example:

1. checkdate (1, 30,2005); Output: (1 means true)

2. checkdate (2, 30,2005); Output: (null means false)

That's it you have learnt about some of the most commonly used date functions in PHP.

Absolutely FREE Web Templates
Check out these quality free web templates and download them without any registration or sign-up!

FREE Web Design Guide
From web design tips & ideas to HTML, CSS Styles, Fireworks & Dreamweaver you'll find all you need to know about effective web site design right here!

Quality Dreamweaver Templates
Professional quality dreamweaver templates in over 20 categories, starting at just $9.95! Instant download & easy customization