954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

current local time

how can i show current local date and time using php??
do i need to use new page or just add in the same page?

and how can i insert time and date that show in the page into my database?

i have search for a while for this, but i still stuck and can't find the solution...

fika
Newbie Poster
16 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

Current local date and time:

http://php.net/manual/en/function.date.php

Note that since PHP 5.1 you have to set timezone for local time either in a format string or by calling date_default_timezone_set() function or by setting it in PHP ini.

http://php.net/manual/en/function.date-default-timezone-set.php
http://www.php.net/manual/en/datetime.configuration.php#ini.date.timezone

To store a date in mysql table you can use the mysql DATE type which I think stores date as a string but I prefer to store dates as Unix timestamp (not mysql timestamp which is different) but this depends on what you use the dates for. For storing Unix timestamp the mysql field tipe is integer.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html

broj1
Posting Whiz
359 posts since Jan 2011
Reputation Points: 29
Solved Threads: 43
 
how can i show current local date and time using php??

Do you mean everybody sees YOUR local time wherever they may be in the world? Or do you wish everybody to see things in their own local time?

I created a date page a while ago - not very good, but it gives you an easy way to play with dates: http://diafol.org/datetime.php#

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

thanks... i mean they can see their own local time..
what i want to do is, when they register, the date and time will be insert into database too.. how can i do that with current local time??

i need to use php, right?? with timestamp or what???

fika
Newbie Poster
16 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

by now, i can show current time and date.. but, still return 0000-00-00 in my database..
how can i fix this error???

fika
Newbie Poster
16 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 


i'm using this code to show current local time in my page.. how can i insert this into my database..?

or i can't use this code??

<?php
$timezone = "Asia/Kuala_Lumpur";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);
echo date('l Y-F-d H:i:s A');
?>
fika
Newbie Poster
16 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

Store the date in your DB as a unix timesdtamp:

time()


If you store dates/times in the user's native timezone, date orders will become messed up. You only need to select the user's tz do this fordisplay purposes.

When a user signs up, they'll be given a choice as to the TZ they want to use - that's stored in the DB in the user's table. So, once they log in, their TZ (or a default one, if they didn't change the setting) is invokes on every page.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You