|
|
 |
Re: FN-FORUM mysql date query
date posted 20th June 2002 16:58
Hi Rob,
My answer t both your queries would be to store the date as a unix
timestamp, either using the internal MySQL UNIX_TIMESTAMP() function or the
time() and mktime() functions in PHP. To convert from a date specified as
19-06-2002 to a unix timestamp I'd use the following code...
$date = "19-06-2002";
list($day, $month, $year) = explode('-', $date);
$timestamp = mktime(0, 0, 0, $month, $day, $year);
...then store $timestamp in an INTEGER field in the MySQL table. When
reading it back, convert from the timestamp to your date using strftim()...
$row = mysql_getch_row($result, MYSQL_ASSOC);
$date = strftime("%d-%m-%Y", $row['dateOfBirth']);
This way, your date is stored in an independant format that you can convert
how you like. The disadvantage is that you lose the ability to perform
SELECT queried using the MySQL DATE_XXX() functions, though a workaround is
possible using unix timestamps!
I hope this helps!
Regards,
Steve
----- Original Message -----
From: "Rob Garbutt" [EMAIL REMOVED]
To: [EMAIL REMOVED]
Sent: Thursday, June 20, 2002 4:11 PM
Subject: FN-FORUM mysql date query
Hi all,
I'm a field using the 'Date' type in a mysql database field. Is it possible
to select a format for the date or can you only use the default date of
2002-06-06.
tia!
Robin Garbutt
Portfolio Art & Design Ltd
Tel - +44 (0) 1204 383822
Fax - +44 (0) 1204 383866
Mob - +44 (0) 7811 185490
e-mail - [EMAIL REMOVED]
For further information please visit us at :-
www.portfoliodesign.net
The contents of this e-mail are confidential to the ordinary user of the
e-mail address to which it was addressed and may also be privileged. If you
are not the addressee of this e-mail you may not copy, forward, disclose or
otherwise use it or any part of it in any form whatsoever. If you have
received this e-mail in error please e-mail the sender.
================================================================
= ************************* SilkPHP ************************** =
= ---------> Free PHP Scripts for your web sites |
 |
|