|
Posted by Joseph Melnick on 07/01/05 21:04
"the good guy" wrote,
"the good guy" <good@thinking> wrote in message
news:42c53772$1@news.starhub.net.sg...
> There is a better way to resolve this.
>
> Instead of using a "human" readable date like 2001-21-06 (which is 21st
> Jun
2001-21-06 is not a correctly formatted MySQL date.
The correct format is: YYYY-MM-DD
2001-06-21 is a MySQL Date representing June 21st 2001
> 2001), you should use Unix Timestamp instead. Conversion can be done via
> http://www.php.net/manual/en/function.mktime.php
>
It is desirable to perform data manipulations and comparisons using database
functionality as these functions are local to the data (Low Latency), they
are written in C(Fast) and understand the data formats natively.
> And whenever you need to display the actual human date, just use date()
> function. date() is able to control the format of the date.
>
The MySQL function: FROM_UNIXTIME(unix_timestamp,format) Would suite your
purpose if you decided to store all timestamps in unix format and need to
produce a human readable date/time from this stored data.
> If you going to set the field of your table to date, you will have to
> comply
> with the MySQL format for date. If you use the Unix Timestamp, you can
> avoid
> using the date field format and use plain old varchar.
>
I strongly disagree, complying with the MySQL formatted date or
unixtimestamp for that matter will allow you to use proven, fast, efficient,
built-in database functionality. Definately a plus when it comes to
reliablity.
A database is more than just a data container.
Joseph Melnick
JM Web Consultants
http://www.jphp.com/
>
> "HawkEye" <sunbed@rocketmail.com> wrote in message
> news:OLydnZ0oeeLAA1zfRVnyvw@pipex.net...
>> Terry wrote:
>> > Joseph Melnick wrote:
>> >
>> >> Terry wrote:
>> >>
>> >> "Terry" <tknospa@wejuggle2.com> wrote in message
>> >> news:42c144fb$1_1@spool9-west.superfeed.net...
>> >>
>> >>> I am using phpMyAdmin to access MySQL for inputting data - built one
>> >>> table - no problems. I am uploading text files using ; as a
>> >>> delimiter. Second table includes a date (configured as date not
>> >>> datetime). I have tried:
>> >>> 2001-21-06;hello; \r\n
>> >>> 20002106;goodby; \r\n
>> >>> '2001-21-06';hello; \r\n
>> >>> '20002106';goodby; \r\n
>> >>>
>> >>> All I get is:
>> >>> Date comment
>> >>> 0000-00-00 hello
>> >>>
>> >>> I have looked at the manual for MySQL and php, googled - this is so
>> >>> simple no one else has a problem, right?
>> >>>
>> >>> TIA
>> >>>
>> >>
>> >>
>> >> Hello Terry,
>> >>
>> >> Did you try to optionally quote the date field on import?
>> >>
>> >> "2005-05-23";hello;
>> >
>> > I have now - same result.
>> > "2001-21-06";hello; \r\n
>> > "20002106";goodby; \r\n
>> > Yields:
>> > Date comment
>> > 0000-00-00 hello
>> > 0000-00-00 goodby
>> >
>>
>> Are you trying to use the current date (ie today) ? If so use curdate()
>> or
>> now(). One is for date and one datetime (I forget which)
>>
>> HTH
>>
>> --
>> Regards
>>
>> Neil
>>
>> Registered Linux User 324599
>> If vegetarians eat vegetables, beware of humanitarians!
>
>
[Back to original message]
|