SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Date

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= 1406564582 

You can use php time stamp generator to find the time stamp of any date

To display current time stamp we have to use time() function like this .
<?Php
 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. stamp.

Displaying current time

We can display current time by using time() functino. Here is the code

echo date(" H:i:s", time());

The output is here 21:53:02

By using JavaScript we can display real time changing clock

Displaying current time & date by using localtime function in PHP

Here is the current time stamp again : 1406564582
From the value above let us display the current date and time by using the date function
echo date("m/d/y",time())
Here is the output showing current date and month value using the above  timestamp.

07/28/14

You can find detail php date today functions and php date formats in other tutorials in this section.

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 :
 28/07/14 : 21:53:02
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");

You can create two demo pages to understand concept of Time stamp.

Using html meta page refresh, create page which will reload itself at every 10 seconds and display the updated timestamp.
Try to display the timestamp in every 10 second duration without reloading the page. ( Use Ajax )

Date Picker by using Calendar

By using JavaScript we can display current month calendar and user can select a date from the calendar to input to a textbox. User can browse to different months of the calendar and select different dates.

User can also select two dates indicating Start date and end date.

Number of User Comments : 40


Google+
Click for more tutorial on Date & Time functions and Applications


More On Date Object
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
Rahul30-03-2010
How to convert 3 text box value in a one variable in PHP
Ankit Tomar06-04-2010
Thanx for the tute specially for Time zone Asia/calcutta
amit chaudhary22-06-2010
thanx for this nice tutorial,it is very helpful for me..
Pritesh30-06-2010
yes its a very good tutoril all problems all easy solved thank you
Jahtex29-08-2010
oh.. what a great tut... the mention of the php build in function date_default_timezone_set(); is a great revelation to my coding life.. once again many thanks to the writer...
Masees Skenderian18-09-2010
iam using function: date("d/m/y : H:i:s", time())
how do i display the time in a 12 hours clock not a 24 hours clock?
smo29-09-2010
Use small ( lower case ) h in place of upper case H. You can read more on date formats.
tiffin02-11-2010
i am using function echo date("g:i");

But the time is early 4 hours from my pc time.How can i synchronize the time so that its the same as my pc time?
Amit06-12-2010
How to use time stamp in cookies
Ernest Darling10-01-2011
You are a life saver buddy but one more thing, How do I store a Timestamp into mysql database so it can later be retrieved as Timestamp?
Anantha Narayanan29-04-2011
Hi, This was very helpful,

I have a doubt in mysql timezones and time-format, see i have a table in DB which has 2 important column which is location and timestamp, in which location can be anything, but i want the timestamp to be same format as it generated, since we have customers from different timezones, which i want the timestamp to be saved as it is, say if GMT it should saved as GMT, if it is pacific , it has to saved as PACIFIC,

Kinldy help me with your suggestions
Chris Kefel22-05-2011
As a newbie php-user, this tutorial helped me a lot.
Thanks
tim02-01-2012
Thanks for the tutorial.
My question is, if i have 2 events . How do l set the code to show the actual event each of the 2 events occured?
malekHaron10-05-2012
thanks a lot bro! its really worked and its great! you sir, should be in the avengers! ;)
Jace25-05-2012
Great tutorial,
Thanks
iqbal iqbal01-09-2012
great one
amith20-09-2012
tnx bro... its really worked.....
PREM19-10-2012
Its very best way to practical success
Victor Olaru15-12-2012
Works perfectly,

Thank you very much,

Best regards
rubab03-04-2013


Every thing is perfect.the thing i want is now to display the time zone of server.Can anyone help me out.

its out put is:

Tue Apr 02 2013 07:32:06 pm (i want time zone to be displayed with this output)
Subhendu16-07-2013
You can use date_default_timezone_get() function to display time zone of the server
Sagar08-01-2014
Thx buddy.... The thing that I was looking for since long time.... Thx much...
Shaan04-06-2014
How to add number of months to an current date
Bryan12-07-2014
wow, thank you been trying to find out how to do this for ages, thanks a lot!
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



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer