Tony wrote:
[color=blue]
> "Chris Hope" <blackhole@electrictoolbox.com> wrote in message
> news:d8rkje$7a7$1@lust.ihug.co.nz...[color=green]
>> Angelos wrote:
>>[color=darkred]
>>> What do you think is the best way to store Dates into a database ?
>>> If you want to keep logs or buckups....
>>>
>>> I am using date('dmYHis')
>>> but I doesn't work really well ...
>>> Is it better to use date(U) ?
>>> Any suggestions ?[/color]
>>
>> Use the date or datetime field type - the exact name of the type
>> depends on your DBMS.
>>[color=darkred]
>>> And if you can let me know how you can Display that date back in the
>>> Screen ![/color]
>>
>> Depending which DBMS you are using there may be a function for
>> formatting the date; in MySQL for example you would use the
>> date_format() function.
>>
>> Otherwise you can use the PHP function strtotime() to change it to a
>> timestamp and then date() to format it as you wish. The downside with
>> this is you are limited to the range of a unix timestamp which is
>> from 1970 to 2038.[/color]
>
> I don't recall date() being limited -
>
> I often use something like $today = date('Y-m-d'); to get a date to
> enter into a MySQL database. And when I have a date value that needs
> translating, I just use string concatenation: $otherdate = $year . '-'
> . $month . '-' . $day; (assuming $year, $month, and $day are numeric,
> of course)[/color]
date() isn't. strtotime() is as it returns a unix timestamp.
--
Chris Hope |
www.electrictoolbox.com |
www.linuxcdmall.com