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:

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

Member Avatar for diafol

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#

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

<?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');
?>
Member Avatar for diafol

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.