Date and time Class , objects and function in PHP

Function Description
DatePHP Date & Time object
createfromformat()Change date format
checkdate()Validating date
date()Required date and time in given format
date_create()Creating date objects
Date IntervalCreating date interval object using standard format
Date Interval formatFormatting date interval output
Adding dateAdding date and time to the date object
Date differenceDifference in days month etc between two date object
Modifying dateChange the date object by adding or subtracting days, months, time etc.
Set DateChanging the date object by adding new date parameters
Set TimeChanging time part of the date object
setISODateSet the ISO Date
setTimestamp()Change the date object by using timestamp
strtotime()Text string of data to timestamp
TimeZone GetGetting time zone set at the server
TimeZone SetSetting a new time zone of the server
Date FormatFormatting the date output
TimeZone ListList of time zones can be used or available
date_get_last_error()Displaying error
gettimeofdayTime elapsed between current time and Epoch time
gettimestamp()Getting Timestamp from date object
datetimeimmutable()Date object original not to change
gmdate()Formatted date output showing GMT date and time
gmmktime()Timestamp using GMT date and time as input
localtime Date , time, year etc as an array
getdate() getting part like month name, date , year etc .
mktime() getting time stamp of input date and time
TimestampDemo of generating timestamp by using date and time as inputs

DEMO :Select Timezone to get current date and time using different formats

Managing date and time user input by datetime-local
Displaying date and time
How to display current time stamp value in a page? By using time stamp we can display the date and time by formatting the time stamp output. Learn how to set the time zone of the server or at the page level.

Validating date and finding date parts from a date string
We need to check the user entered date value in any web page before using in our script. For this php built in date function checkdate can be used. This function returns true if the date is a valid date. This function also takes care of leap years and other date restrictions.

Previous dates or advance dates from today
How to get date parts to display previous or advance dates by calculating from the present date.

Drop down list box for date month selection
It is easy for a user to select month, date etc from a drop down list box than entering them in a text box. Here the data entered by the user will be under control as from a given options the user has to select one.

2nd and 4th Saturday of the month
Display 2nd and 4th Saturday of the month. For any input month and year display the 2nd and 4th Saturday.

Date Difference
By using mktime function we can get the difference in day or month or year between two dates.

Date value from string variable
From a string variable consist of months or days we can use array split command to get the date parts.


Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net



    it very helpfull for me.


    this is a very good website for all developers and new learners.


    Thanks for the example of date I need it very much.
    Dosmanking Khan


    Really ,,it is very very helpful website..specialy for's tutorial is so nice ,,,easy to understand..eventually it save my providing some codeing demo..ok thank's admin..


    The date validation part was quite easy to understand.But my problem still lies in the fact that within a date that is to be entered in any format,if after one part(as in date) we use the back-slash(/) separator and after the next part(in between month


    how to store the system date and time into the mysql database.


    ei im sulik from the Philippines, could someone help me? i dont know why my date function produces wrong results? my system time is fine and correct. but when i echo the date function, something like this... date("H:i:s"); it outputted wrong result which is 8 hours late? date function base its time from the server not from the system time right? if it's that's the case then how can i set my server time? im using wamp server by the way. Replies for my long time problem would be much appreciated. tnxs in advance.


    There is a time adjustment setting to take care of global time zones, that is inside your PHP.ini file. This setting will display the time by reading the server time and then adding the time zone adjustment. You need to change this setting.


    tnxs for the reply smo. i tried the php.ini file and set date.timezone = Asia/Manila but nothing happens and produces wrong 8 hours late results. so ive searched the net and found out that there is a code that you can explicitly set the timezone, this is the code.. date_default_timezone_set('Asia/Manila'); and after adding this code the date function outputs correct results... I dont know why it doesn't work on the php.ini file. ive done many php.ini setting in the past and this is the first time that i encounter some problems. Any ideas?


    i like php thats y its helpful for me


    this is a very good website for all developers and new learners
    Swapnil Menkar


    i like this website, its so useful to new programmer.

    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer