473,671 Members | 2,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Last Day of Year Date Bug?

Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?

<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));?>

AS
Dec 31 '07 #1
10 3275
ashore wrote:
Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?

<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));?>

AS
Interesting. Looks like it may be a bug.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 31 '07 #2
On Mon, 31 Dec 2007 14:18:34 +0100, Jerry Stuckle
<js*******@attg lobal.netwrote:
ashore wrote:
>Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?
<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y"))); ?>
AS

Interesting. Looks like it may be a bug.
Nope,
date('m')-1 = 11
date('d') = 31

31-11-2007 = 01-12-2007 as far as php is concerned.

Not 'end of a year' bug, but '31st of every month' bug (well, feature I'd
say, I know what to expect), with a few bonus dates in march.
--
Rik Wasmus
Dec 31 '07 #3
Rik Wasmus wrote:
On Mon, 31 Dec 2007 14:18:34 +0100, Jerry Stuckle
<js*******@attg lobal.netwrote:
>ashore wrote:
>>Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?
<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));? >
AS

Interesting. Looks like it may be a bug.

Nope,
date('m')-1 = 11
date('d') = 31

31-11-2007 = 01-12-2007 as far as php is concerned.

Not 'end of a year' bug, but '31st of every month' bug (well, feature
I'd say, I know what to expect), with a few bonus dates in march.
Ah, yes. Now I remember why I don't do it this way - it's been so long
I forgot.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Dec 31 '07 #4
Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive').

While correcting this will prbly break a lot of applications, mebbe
it's time for another date set of functions.

What DO you guys use to 'go back one month' reliably?

-AS
Dec 31 '07 #5
On Mon, 31 Dec 2007 17:28:11 +0100, ashore <sh*****@gmail. comwrote:
Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive')..
Well, it's something I rather depend on most of the time actually. How do
you propose it should handle '31-11-XXXX'? An error/exception perhaps,
that would be justifiable. Just setting it back to 30-11 would be
inexcusable.
While correcting this will prbly break a lot of applications, mebbe
it's time for another date set of functions.

What DO you guys use to 'go back one month' reliably?
Depends on the use. In some cases, taking 01-12-2007 as one month before
31-12-2007 is just what I want. In your context, why do you bother with
the day part?

print date("M `y", mktime(0, 0, 0, date("m")-1, 1,date("Y")));
--
Rik Wasmus
Dec 31 '07 #6
In article
<06************ *************** *******@l6g2000 prm.googlegroup s.com>,
ashore <sh*****@gmail. comwrote:
Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive').

While correcting this will prbly break a lot of applications, mebbe
it's time for another date set of functions.

What DO you guys use to 'go back one month' reliably?
First we should ask - what does your question mean?

Does "go back one month" mean go back 31 days or does it mean "go to
same numbered day of previous month"?

Each definition has its problems. 2nd March minus 31 days takes you to
January. From 31st Dec, there *is no* same numbered day in previous
month.
Dec 31 '07 #7
On Dec 31, 8:28 am, ashore <shor...@gmail. comwrote:
Feature or bug, that's pretty bad (where 'bad' == 'non-intuitive').

While correcting this will prbly break a lot of applications, mebbe
it's time for another date set of functions.

What DO you guys use to 'go back one month' reliably?

-AS
I use 1 as the day, if I want to find the last month, or a simple
$lastmonth = ($curmonth == 1,12, $curmonth -1);

The date with mktime is great for calculating out an arbitrary date
such as add 30 days to the current date, etc. It's not a bug, but a
great feature, if you understand how it works.

Here is some date arithmetic I posted that uses mktime, just to give
you an idea.

http://groups.google.com/group/comp....d94e81f2ec396a

Jan 1 '08 #8

"ashore" <sh*****@gmail. comwrote in message
news:d6******** *************** ***********@s12 g2000prg.google groups.com...
Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?

<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y")));?>
it's a known bug.

php uses approximation methods to arrive at a date. most of the time it
works. essentially, php assumes an average of 30 days in every month. you
can use 12/30/2007 23:59:59 and subtract one month from it and get Nov
`07...

$date = strtotime('12/30/2007 23:59:59');
// echo date('M `y', $date); // Nov `07
// now, watch this...
$date = strtotime('+1 second', $date);
// you guessed it...Dec `07

i tend to avoid this problem by getting the first of the month and then
doing calculations from that (in similar contexts). php tends to correct the
30 day averaging bug when using the first of any month...at least i've never
had a problem like this when using the following:

$date = strtotime('12/31/2007 23:59:59');
$date = strtotime(date( 'm', $date) . '/01/' . date('Y', $date));
echo date('M `y', strtotime('-1 month', $date));

hth,

me
Jan 2 '08 #9
On Wed, 02 Jan 2008 19:09:41 +0100, Steve <no****@example .comwrote:
>
"ashore" <sh*****@gmail. comwrote in message
news:d6******** *************** ***********@s12 g2000prg.google groups.com....
>Guys, the line below just returned "Dec 07" as the date for one month
back from today. Hardly life-threatening, but any thoughts?

<?php print date("M `y", mktime(0, 0, 0, date("m")-1, date("d"),
date("Y"))); ?>

it's a known bug.

php uses approximation methods to arrive at a date. most of the time it
works. essentially, php assumes an average of 30 days in every month. you
can use 12/30/2007 23:59:59 and subtract one month from it and get Nov
`07...
This statement is utter nonsense. Why waste a perfectly good allready
given explanation with garbage Steve? For your pleasure, the proof (thank
god for february, be carefull about leap years..):

<?php
date_default_ti mezone_set('Eur ope/Amsterdam');
$date = mktime(12,0,0,3 ,1,2007);//1 march 2008
print date("M `y", mktime(0, 0, 0, date("m",$date)-1, date("d",$date) ,
date("Y",$date) ));
?>

According to your 'approximation method', this should return january, as
31-01-2007 is 30 days before the 1st of march. It does not. The real
answer is still: 'if in mktime the nth day of a month doesn't exist, PHP
will assume you mean the (n-<days in month>)th of the next month'.(Or in
case of negative numbers, the (n+<days in month>)th of the previous month.
Similarly:

<?php
date_default_ti mezone_set('Eur ope/Amsterdam');
//march the 63 is assumed to be may 2nd
print date("d M `y", mktime(0, 0, 0, 3, 63, 2007));
//february the 0th is assumed to be january the 31st
print date("d M `y", mktime(0, 0, 0, 2, 0, 2007));
//april the -1th is assumed to be march the 30th
print date("d M `y", mktime(0, 0, 0, 4, -1, 2007));
//the 0th month is assumed to be december
print date("d M `y", mktime(0, 0, 0, 0, 1, 2007));
//the -1th month is assumed to be november
print date("d M `y", mktime(0, 0, 0, -1, 1, 2007));
?>

If you have imagined an answer to a question, please be sure it's the
right one before spreading it around.
i tend to avoid this problem by getting the first of the month and then
doing calculations from that (in similar contexts).
Which was allready suggested.
--
Rik Wasmus
Jan 2 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9558
by: John | last post by:
If anyone can help me out with a good way to do this in javascript I would greatly appreciate it. I need to compute three dates in javascript - all of which relate to a given date, say todays date. I need to calculate: 1. same day last year(that is, if today is friday, i want the date of the friday 52 weeks ago)
3
6612
by: Melissa | last post by:
I have this table: TblProjectYear ProjectYearID ProjectYearStartDate ProjectYearEndDate The Project Year will always span across December 31; for example 9/1/04 to 6/30/05. How do I build a combobox based on this table that will display all the months between the StartDate and the EndDate for a given ProjectYearID and when a selection is made, the full date of the last day of the selected
7
6032
by: MLH | last post by:
Public Function GetLastDayOfMonth(ByVal dtDay As Date) As Date '************************************************************************** ' Accepts a date. Determines month & year of the date. Returns ' the date of the last day of that month (in the same year) '************************************************************************** GetLastDayOfMonth = DateSerial(Year(dtDay), Month(dtDay), 31) End Function If I enter dtDay value of...
0
2854
by: Lee Harr | last post by:
I wrote a function to return the first date of a given week (and a few related functions) : -- return the first date in the given week CREATE or REPLACE FUNCTION week_start(integer, integer) RETURNS date AS ' DECLARE pyear ALIAS FOR $1; pweek ALIAS FOR $2;
5
4277
by: rjfjohnson | last post by:
Hey, Today is Thursday 16-Feb-06. The same thursday last year is 17-Feb-05. Because I am comparing daily sales between years, I need to know the date of the same weekdayname as last year, so that I am comparing Saturdays with Saturdays, Sundays with Sundays, etc ie, 16-feb-06 goes to 17-feb-05 28-july-06 goes to 27-july-05 and so on
4
48211
by: laredotornado | last post by:
Hi, Using PHP 4, if I have a date, what is a function I could use to give me a date that represents the first day of that month? For example, if my date were "3/19/2006 8:00", I would want my function to return "3/1/2006 8:00". Similarly what function would I use to return the last day of the month? In the above example, the output I would want returned is "3/31/2006 8:00". Thanks, -
6
9440
by: phforum | last post by:
If user input the date is 2006-07-01. How to convert it to last year 2005-07-01? Thanks
1
2179
by: Svetac | last post by:
Hi, I use a script that shows when the page was last modified. It works fine for just one html file. The thing I would like to do is that the script shows me of last modified file in root directory. For example if I change something in gallery.html or feed.xml, I would like to see that date of change in index.html under last modified date. Could someone help me please. Thanks in advance. The script that I use now:
3
6116
by: ats | last post by:
Does anybody have any sample code for calculating the date for teh last Friday in each month. TIA -- ats@jbex When an old lady got hit by a truck I saw the wicked gleam in your eyes
0
2360
by: marlberg | last post by:
Platform: Windows2000, WindowsXP, Windows Vista, etc Language: C#, ASP.NET Pre-compiled Libraries: Enterprise Library 3.0 full I have a requirement to implement in and display in C# and ASP.NET a DataGrid with Updatable rows based on a date retrieved from a data table in SQL Server. Below is the design algorithm. 1. Retrieve the Max(rundate) From MyDataTable 2. If the current month -1 = rundate .month from step 1 then 2a. ...
0
8478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7439
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6230
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4409
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1810
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.