Re: Date handling
| From: | Ryan | Date: | Tue, 16 Nov 2004 16:13:57 +0000 |
| Subject: | Re: Date handling | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-202175@lists.php.net to get a copy of this message | ||
Yes, but time() returns a Unix timestamp which has a limit of 2038. For
example, what if I would like to calculate the date of 40 years from today?
I can't do that with the normal PHP date functions. I would have to use
PEAR Date or something similar, which is my original question - of what is
the 'official' PHP way to handle this as calculations with dates is a common
thing to do.
Thanks,
Ryan
"Mike" <php@crazyted.com> wrote in message
news:20041116145505.1D0FE6AE98B@host50a.simplicato.com...
> 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@hotmail.com]
> Sent: Tuesday, November 16, 2004 9:23 AM
> To: php-general@lists.php.net
> Subject: Re: [PHP] 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@nc.rr.com> wrote in message
> news:419A030E.3010203@nc.rr.com...
>> <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