note 79619 added to function.mktime

From: Date: Wed, 05 Dec 2007 19:43:53 +0000
Subject: note 79619 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-132855@lists.php.net to get a copy of this message
To gather a date from the database where the date data are grouped accordingly: Month representation $group_name . 'mon' (named after 'mon' key returned by the getdate() function) Day representation $group_name . 'mday' (named after 'mday' key returned by the getdate() function) Year representation $group_name . 'year' (named after 'year' key returned by the getdate() function) Hours representation $group_name . 'hours' (named after 'hours' key returned by the getdate() function) Minutes representation: $group_name . 'minutes' (named after 'minutes' key returned by the getdate() function) Seconds representation $group_name . 'seconds' (named after 'seconds' key returned by the getdate() function) to calculate a date('F m, Y h:i:s) format, you can use this function, which passes the date by reference. <?php function sqldate(&$date,$query,$group_name,$timezone,$line) { /* Function statement: Calculates a date in date('F m, Y h:i:s') format from numerical data coming from a database and adjusts for time zones Input $query: Query the database is supposed to process $group_name: Name of the group that holds the names (such as viewmon, viewmday, viewyear, etc. $timezone: Time zone of the user $line: __LINE__ constant called in the function in case of an error $file: global variable that calls the file name defined in the file where this function is used Process Run query using mysql_query() and store to $result, or die("MySql failure on line $line in $file: " . mysql_error()) if ('Limit 0,1' is found in the query) { Get the row information using one mysql_fetch_assoc() $date=date('F m, Y h:i:s',mktime($row[$group_name . 'hours']+$timezone, $row[$group_name . 'minutes', $row[$group_name . 'seconds', $row[$group_name . 'mon'], $row[$group_name . 'mday'], $row[$group_name . 'year']); } else { Loop [while(mysql_fetch_array($result)] $date[]= $date[]=date('F m, Y h:i:s',mktime($row[$group_name . 'hours']+$timezone, $row[$group_name . 'minutes', $row[$group_name . 'seconds', $row[$group_name . 'mon'], $row[$group_name . 'mday'], $row[$group_name . 'year']); End Loop } Output $date, passed by reference Assumptions Time zone is of type int, not of type float //some time zones are half an hour To adjust, just add (int) 60*($timezone-floor($timezone)) to minutes //should result in 30 minutes Time zone is relative to GMT */ $result=mysql_query($query) or die("Failure of sqldate() on $line in $file: " . mysql_error()); if(eregi('LIMIT 0,1',$query)) { $row=mysql_fetch_assoc($result); $date=gmdate('F m, Y h:i:s',mktime($row[$group_name . 'hours']+$timezone, $row[$group_name . 'minutes'], $row[$group_name . 'seconds'], $row[$group_name . 'mon'], $row[$group_name . 'mday'], $row[$group_name . 'year'])); } else { while($row=mysql_fetch_assoc($result)) { $date[]=gmdate('F m, Y h:i:s',mktime($row[$group_name . 'hours']+$timezone, $row[$group_name . 'minutes'], $row[$group_name . 'seconds'], $row[$group_name . 'mon'], $row[$group_name . 'mday'], $row[$group_name . 'year'])); } } } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 66.27.16.36 ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- https://master.php.net/note/edit/79619 Del: integrated -- https://master.php.net/note/delete/79619/integrated Del: useless -- https://master.php.net/note/delete/79619/useless Del: bad code -- https://master.php.net/note/delete/79619/bad+code Del: spam -- https://master.php.net/note/delete/79619/spam Del: non-english -- https://master.php.net/note/delete/79619/non-english Del: in docs -- https://master.php.net/note/delete/79619/in+docs Del: other reasons-- https://master.php.net/note/delete/79619 Reject -- https://master.php.net/note/reject/79619 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#132855) next »