johnbruce Posted May 1, 2007 Share Posted May 1, 2007 Hi all, I currently have the following code that writes values back to a mysql database, as you can see the last 2 fields are date and time. The date field works fine and writes the current date back to the db, how do I write the current time back to the last field? $date = date("Y-m-d "); $query = "INSERT INTO applicants VALUES ('','$title','$first','$last','$phone','$mobile','$site','$email','$avaliable','$experience','$date','time()')"; Regards, John Link to comment https://forums.phpfreaks.com/topic/49510-current-time/ Share on other sites More sharing options...
clown[NOR] Posted May 1, 2007 Share Posted May 1, 2007 date("h:i:s a") <- show's 12hrs with lowercase am/pm at the end date("H:i:s") <- shows 24hrs without am/pm Link to comment https://forums.phpfreaks.com/topic/49510-current-time/#findComment-242664 Share on other sites More sharing options...
johnbruce Posted May 1, 2007 Author Share Posted May 1, 2007 Thanks, It wrote back a time but it wasn't our local time. Any idea how to solve this? Link to comment https://forums.phpfreaks.com/topic/49510-current-time/#findComment-242675 Share on other sites More sharing options...
clown[NOR] Posted May 1, 2007 Share Posted May 1, 2007 hmm.. i'm not sure, but it might be that since the php is server-side scripting it returns the current time on the server... but i belive, correct me if I'm way off here, that JavaScript will get the current time from the users computer Link to comment https://forums.phpfreaks.com/topic/49510-current-time/#findComment-242693 Share on other sites More sharing options...
johnbruce Posted May 2, 2007 Author Share Posted May 2, 2007 I'm not sure. Is there anyway to add a set amount of hours to the time before it gets submitted to the database? For example, the server time + 5 hours Link to comment https://forums.phpfreaks.com/topic/49510-current-time/#findComment-243396 Share on other sites More sharing options...
taith Posted May 2, 2007 Share Posted May 2, 2007 here... just activate this function... it'll change your servers default timezone :-) <?php function set_timezone($timezone="0"){ switch($timezone){ case "-12": date_default_timezone_set('Etc/GMT+12'); break; case "-11": date_default_timezone_set('Etc/GMT+11'); break; case "-10": date_default_timezone_set('Etc/GMT+10'); break; case "-9": date_default_timezone_set('Etc/GMT+9'); break; case "-8": date_default_timezone_set('Etc/GMT+8'); break; case "-7": date_default_timezone_set('Etc/GMT+7'); break; case "-6": date_default_timezone_set('Etc/GMT+6'); break; case "-6": date_default_timezone_set('Etc/GMT+5'); break; case "-4": date_default_timezone_set('Etc/GMT+4'); break; case "-3": date_default_timezone_set('Etc/GMT+3'); break; case "-2": date_default_timezone_set('Etc/GMT+2'); break; case "-1": date_default_timezone_set('Etc/GMT+1'); break; case "0": date_default_timezone_set('GMT'); break; case "1": date_default_timezone_set('Etc/GMT-1'); break; case "2": date_default_timezone_set('Etc/GMT-2'); break; case "3": date_default_timezone_set('Etc/GMT-3'); break; case "4": date_default_timezone_set('Etc/GMT-4'); break; case "5": date_default_timezone_set('Etc/GMT-5'); break; case "6": date_default_timezone_set('Etc/GMT-6'); break; case "7": date_default_timezone_set('Etc/GMT-7'); break; case "8": date_default_timezone_set('Etc/GMT-8'); break; case "9": date_default_timezone_set('Etc/GMT-9'); break; case "10": date_default_timezone_set('Etc/GMT-10'); break; case "11": date_default_timezone_set('Etc/GMT-11'); break; case "12": date_default_timezone_set('Etc/GMT-12'); break; } } set_timezone('-5'); ?> Link to comment https://forums.phpfreaks.com/topic/49510-current-time/#findComment-243411 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.