SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

PHP TIME STAMP and DATE function


PHP time stamp is a numeric value in seconds  between the time at present and the value at Unix Epoch (January 1 1970 00:00:00 GMT).   This time of January 1 1970 00:00:00 GMT is taken as base for all time stamp calculations.  Below is the time stamp or the number of seconds lapsed after January 1 1970 00:00:00 GMT and when this page is loaded ( or opened by you). You can refresh this page to see the current time stamp. Press the refresh button of your browser to reload this page to see the current time stamp.

Current time stamp= 1268949237

You can use php time stamp generator to find the time stamp of any date, month, year with hour minute and seconds

In PHP the function giving the current time stamp value is  time(). So we can write a line like below to get the current time stamp value.

<? echo time(); ?>

This line will print the value of current time stamp as displayed at the top. Time stamp is used in many PHP applications and from time stamp the current date and many different date format can be taken by using different functions in PHP.  We will display the time stamp first and then use the code to display the current date from the time stamp.
Related Tutorial
PHP Date Format
PHP Date Today
Time Stamp Generator


Here is the current time stamp : 1268949237

We used echo time() to display the above line.

From the value above let us display the current date and time by using the date function

echo date("m/d/y",time())

You can find detail php date today functions and php date formats in other tutorials in this section.Here is the current date and month value using the above  timestamp. 03/18/10
If you want to display the current time along with the date then change the format of the date function like this
date("d/m/y : H:i:s", time())
the out put of this will be like this : 18/03/10 : 16:53:57

Don't forget to refresh this page to see how the value changes.

Please note that the current date and time value displayed will be affected by default time zone set in your php.ini file of the server.

If you are testing this script in your local machine then take care of time zone setting in your php.ini file is set to your time zone.

You can change your time zone setting at your script page level by using this command

date_default_timezone_set ("Asia/Calcutta");

Or ( one more example )

date_default_timezone_set ("America/Denver");



Further readings
PHP Date & Time functions
PHP Date Time
Validating Date: Checking if date exist
PHP Date Today
PHP yesterday and previous 7 days from today
PHP Date Format
Time stamp generator
Date selection drop down list box
mktime function to generate time stamp
Difference in Two dates by using mktime function
Finding month, weekday, day of the year etc for any date value
Breaking the date string to get month date and year using array













biswa07-01-2009
Nice tutorial.
Alex14-03-2009
thanks, this tutorial really helped :)
wilfer16-03-2009
I found what I have been looking for
Tanmoy30-04-2009
really nice tutorial
biraj27-05-2009
Helped me a lot :)
Amol Bhavsar08-06-2009
Nice Article
sunil28-06-2009
thanks,excellent tutorial.
neha02-07-2009
thanks it help me alot:)
wpbweb20-08-2009
Thanks this is the only code that actully displayed the current time.
ganesh31-08-2009
nice tutorial...
sresti08-11-2009
excellent tutorial and easy to read and easy to understand and more flexible to even beginers also..
Jarnail24-11-2009
Thanks, Such a good tutorials. really help to convert time to date format
drmd - pmai.tk31-12-2009
pretty interesting tutorial but i have a nota ..
while
# echo time() # displays current time-stamp,
# echo date("m/d/y",time()) # displays current time in the SERVER, e.g. her it s GMT - 6
so to display a GMT current time we have to add a sum of 6*60*60 to the time-stamp ..
burnquiss29-01-2010
how to save my date in to my sql please, give tutor tq

manohar yadav15-02-2010
its realy very helpful for me..if is there any rating then i rate it to 80% fro javascript.
harold02-03-2010
nice one
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
Date & Time
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.