RE: Date handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ryan,

I had those problems in the past and to simply avoid the matter altogether,
when I store dates I just do so with the time() function.

$cur_date = time();

That way, when I poll the DB, I have a timestamp that I can then use date()
to format in whatever manner I wish.

I haven't run into any problems doing it this way.

About your specific question, if you want to use your preexisting date
format you'll have to do some string manipulation to pull apart the month,
date and year and then format it how you want to. You'll likely have to use
a switch to swap the month from the numeric representation to the text
abbreviation.

But no matter what you do, if you want some flexibility, you'll have to
either change the format in the DB or just do it all on the fly in your
script because the date() function expects you to pass it a timestamp.

You may be able to come up with something clever using strtotime() however.
http://us2.php.net/manual/en/function.strtotime.php

-M

-----Original Message-----
From: Ryan [mailto:rbro@xxxxxxxxxxx] 
Sent: Tuesday, November 16, 2004 9:23 AM
To: php-general@xxxxxxxxxxxxx
Subject: Re:  Date handling

Hi Robert,

Storing the date in my database isn't the issue I'm running into.  The 
problem I'm having is that if I have a date "1950-01-01", how can I display 
it in my PHP script as "Jan 1, 1950".  Or if I have "2040-04-01", how to get

it to display as "Apr 1, 2040".  I can't see a way to do that right now in 
the core PHP code using the built-in date functions.

Thanks,
Ryan


"Robert Sossomon" <LoneWolf@xxxxxxxxx> wrote in message 
news:419A030E.3010203@xxxxxxxxxxxx
> <SNIP>
>> <?php
>> echo strtotime('1950-01-01');
>> ?>
>> I'm guessing Red Hat Enterprise or at least the kernel I'm using (which 
>> is
>> the latest RH kernel) qualifies under the Linux category above.  Also, 
>> with
>> the application I'm writing, I need to deal with dates after 2038 too. 
>> So
>> that is why I'm investigating alternatives - just because I'd like 
>> something
>> that would definitely work on any platform and is 'official' as much as
>> possible - rather than have my date handling be OS-specific.
> <SNIP>
>
> How are you entering the date into the Table?  Could you not just rewrite 
> the page so that the date information is entered differently, then format 
> it in the correct way and dump it into the table?  I would think that it 
> would work to solve your problem in dealing with dates, but that is just a

> guess here.
>
> HTH,
> Robert 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux