Re: Date functions
| From: | Jeff | Date: | Tue, 15 Aug 2000 05:13:29 +0000 |
| Subject: | Re: Date functions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11738@lists.php.net to get a copy of this message | ||
Aragon,
I posted a request about this over the weekend to see if anyone
had any code they wanted to share and since there were no replies,
I just went ahead and wrote my own.
The nice thing is that the mktime() function very neatly handles
the calculations you need. To add a month, for example, just add
n months to whatever you have. For example, start with month 12,
add 3, you get 15. Plug month 15 into the function and automatically
figures out what you're trying to do, and it comes up with March
of the next year. Read the documentation about this function,
especially where it refers to handling out-of-range days and months.
Month zero goes to December of the previous year; month 13 goes to
January of the next year; the 32nd of January goes to Feb. 1 and
so on. I've written a set of functions, tested them and some are
already in production and most use this function to do their
magic.
Jeff
AragonX wrote:
>
> Well, yes and no. I should have been more specific. That easily solves
> the day and week adds and subtracts. But I run into an issue when I need
> to add and subtract months. I can work something out but I wanted to know
> if there was one clean way to deal with it.
>
> Perhaps the capability is there and I'm just missing it but I didn't see
> an obvious way to do months. Like finding the last day of the month.
>
> On Mon, 14 Aug 2000, Rolle, Ted wrote:
>
> > I vacillate between saying, "RTFM" and leaving it at that, or (more civilly)
> > say "For a good time, go to
> > http://www.php.net/manual/ref.calendar.php. The
> > JD is exactly what you're looking for.
> >
> > -----Original Message-----
> > From: AragonX [mailto:aragonx@dcs.penguinpowered.com]
> > Sent: Monday, August 14, 2000 10:09 AM
> > To: php-general@lists.php.net
> > Subject: [PHP] Date functions
> >
> >
> > Help. I want to add dates together and find out the day differences
> > between to dates. Is there an easy way to do that? How about adding days
> > to a date? I need some advanced date functions but I didn't see anything
> > in the PhP manual.
> >
> >
> >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net