PHP offers procedural date/time functions plus DateTime and DateTimeImmutable objects. For new code, DateTimeImmutable is often easier to reason about because operations return a new object instead of changing the original.
$now = new DateTimeImmutable('now', new DateTimeZone('Asia/Kolkata'));
echo $now->format('Y-m-d H:i:s T');Use the function/reference links below for formatting, parsing, intervals, time zones and timestamps.
Core date/time tutorials in this hub now use current PHP examples first, with legacy teaching examples retained where they still explain useful behavior.
| Function | Description |
|---|---|
| Date | PHP Date & Time object |
| createfromformat() | Change date format |
| checkdate() | Validating date |
| date() | Required date and time in given format |
| date_create() | Creating date objects |
| Date Interval | Creating date interval object using standard format |
| Date Interval format | Formatting date interval output |
| Adding date | Adding date and time to the date object |
| Date difference | Difference in days month etc between two date object |
| Modifying date | Change the date object by adding or subtracting days, months, time etc. |
| Set Date | Changing the date object by adding new date parameters |
| Set Time | Changing time part of the date object |
| setISODate | Set the ISO Date |
| setTimestamp() | Change the date object by using timestamp |
| strtotime() | Text string of data to timestamp |
| TimeZone Get | Getting time zone set at the server |
| TimeZone Set | Setting a new time zone of the server |
| Date Format | Formatting the date output |
| TimeZone List | List of time zones can be used or available |
| date_get_last_error() | Displaying error |
| gettimeofday | Time 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 |
| Timestamp | Demo of generating timestamp by using date and time as inputs |
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| mahesh | 15-02-2009 |
| it very helpfull for me. | |
| keshav | 04-03-2009 |
| this is a very good website for all developers and new learners. | |
| gOzaru | 12-05-2009 |
| Thanks for the example of date I need it very much. | |
| Dosmanking Khan | 20-06-2009 |
| Really ,,it is very very helpful website..specialy for beginners..it's tutorial is so nice ,,,easy to understand..eventually it save my career..by providing some codeing demo..ok thank's admin.. | |
| Rajat | 23-06-2009 |
| 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 | |
| pandiyan | 01-08-2009 |
| how to store the system date and time into the mysql database. | |
| sulik | 27-09-2009 |
| 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. | |
| smo | 27-09-2009 |
| 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. | |
| sulik | 27-09-2009 |
| 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? | |
| azhar | 11-05-2010 |
| i like php thats y its helpful for me | |
| kunjan | 07-09-2011 |
| this is a very good website for all developers and new learners | |
| Swapnil Menkar | 05-05-2012 |
| i like this website, its so useful to new programmer. | |