This is a discussion on Re: [PHP] Date Issue within the PHP General forums, part of the PHP Programming Forums category; Thank you again Dan. Thought never crossed my mind the day being the 31st. That fixed it. Richard L. Buskirk ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Thank you again Dan. Thought never crossed my mind the day being the 31st. That fixed it.
Richard L. Buskirk On Mon, Mar 31, 2008 at 4:15 PM, <admin@buskirkgraphics.com> wrote: > I tried that a big no go. > Seems if I do a +1 i get 2 months from now and a -1 gives me the current month. > > > > $month = date("F", mktime(0,0,0, date('m'), date('d'), date('Y'))); > $zomonth = date("F", mktime(0,0,0, date("m")-1, date("d"), date("Y"))); > $nmonth = date("F", mktime(0,0,0, date(m)+1, date(d), date("Y"))); > > > $month echo's MARCH should be Feb > $zomonth echo's MARCH should be March > $nmonth echo's MAY this should be April That's because you're using today's date('d');, which is 31. February doesn't have 31 days, nor does April, so mktime() forces them to the following month to correct the error. -- </Daniel P. Brown> Forensic Services, Senior Unix Engineer 1+ (570-) 362-0283 |
|
|||
|
On Mon, Mar 31, 2008 at 4:24 PM, <admin@buskirkgraphics.com> wrote:
> Thank you again Dan. Thought never crossed my mind the day being the 31st. That fixed it. Thank Andrew Ballard, actually. He said it even before I did. I'm getting slow in my old age! ;-P -- </Daniel P. Brown> Forensic Services, Senior Unix Engineer 1+ (570-) 362-0283 |
|
|||
|
If you want the DAY before, you can use the -1 for the day, and get
what you want. mktime() will "wrap" the month as needed. But, yeah, if you try to hit a MONTH before by putting in a month before AND the day, it will "slingshot" back and forth to get what you don't want. If you want the MONTH before, I *suspect* you can use date('m') for the argument, and do NOT provide a day, and it may do what you want. But for sure, if you use ONE (1) for the day, and then -1 for the month it will do what you want, since every month has a ONE (1) day. Anything 1 from 28 will work fine, actually, but using 1 is probably clearest: $today = mktime(); $tomorrow = mktime(1, 0, 0, date('m'), date('d') + 1); $next_month = mktime(1, 0, 0, date('m') + 1, 1); $last_month = mktime(1, 0, 0, date('m') - 1, 1); I've been using these for a web calendar since nineteen-ninety-mumble, and they've worked fine, through leap years. You can view the source to the PDF version here: http://uncommonground.com/events.phps The HTML version has the exact same stuff at the top. http://uncommonground.com/events.htm Feel free to page through as many months/years past/present and future to see that it works. Since it's a 32-bit machine, it does conk out in March 2038. I'm fairly confident our web-server will be a 64-bit machine before we book any (real) events for 2038... You can ignore my test events in January 2038 :-) On Mon, March 31, 2008 3:24 pm, admin@buskirkgraphics.com wrote: > Thank you again Dan. Thought never crossed my mind the day being the > 31st. That fixed it. > > Richard L. Buskirk > > > > > > > > > > > > > > > On Mon, Mar 31, 2008 at 4:15 PM, <admin@buskirkgraphics.com> wrote: >> I tried that a big no go. >> Seems if I do a +1 i get 2 months from now and a -1 gives me the >> current > month. >> >> >> >> $month = date("F", mktime(0,0,0, date('m'), date('d'), date('Y'))); >> $zomonth = date("F", mktime(0,0,0, date("m")-1, date("d"), >> date("Y"))); >> $nmonth = date("F", mktime(0,0,0, date(m)+1, date(d), date("Y"))); >> >> >> $month echo's MARCH should be Feb >> $zomonth echo's MARCH should be March >> $nmonth echo's MAY this should be April > > That's because you're using today's date('d');, which is 31. > > February doesn't have 31 days, nor does April, so mktime() forces > them to the following month to correct the error. > > -- > </Daniel P. Brown> > Forensic Services, Senior Unix Engineer > 1+ (570-) 362-0283 > -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/from/lynch Yeah, I get a buck. So? |
![]() |
| Thread Tools | |
| Display Modes | |
|
|