note 79619 deleted from function.mktime by felipe
| From: | felipe@php.net | Date: | Sun, 06 Jan 2008 12:08:13 +0000 |
| Subject: | note 79619 deleted from function.mktime by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134863@lists.php.net to get a copy of this message | ||
Note Submitter: Sabrina Sollmann (reportingscience.com)
----
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']));
}
}
}
?>