Goto:My Web Site, Makemytaste.com

Sunday, May 23, 2010

current date and time in php from apache server

there is certain situation for logging the current time in mysql.. in such situation the mysql 'now()' function is not used by me.
since the mysql server time may be different than apache server .. some application may be using remote database access rather than localhost. in such situations too i use to go for a a function in php.

try this function such that the function is declared above the place where you are calling the function.
declare this function and just call this function. you will get the current apache server time.

function get_date(){
        $timestamp=strftime("%Y-%m-%d %H:%M:%S %Y");
        $curr=strftime("%Y-%m-%d %H:%M:%S", strtotime($timestamp));
        return $curr;
        }
?>
       
call this function such that


$currenttime=get_date();
print  $currenttime;

?>
 the  output of this function will be the current date and time in a format for mysql " yyyy-mm-dd 00:00:00 " . you can simply enter this data to mysql datetime field.

0 comments:

Post a Comment