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...

Current local date and time:

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.

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.

Member Avatar

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:

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???

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

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??

$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');
Member Avatar

Store the date in your DB as a unix timesdtamp:


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 for display 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.