473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem with strtotime()

Hi,
I do something like this:
$month = date('m', strtotime('2004-09-30 +5 months'))

This give me 03 (March), but 09 (September) + 5 months should give me 02
(February)

It's bug or I thing wrong?

--
Dawid Szałęga
Jul 17 '05 #1
3 2220
Dawid Szałęga schrieb:
$month = date('m', strtotime('2004-09-30 +5 months'))

This give me 03 (March), but 09 (September) + 5 months should give me 02
(February)


There is no such date as 2005-02-30, so you reach the next month.

Regards,
Matthias
Jul 17 '05 #2
"Matthias Esken" <mu******************@usenetverwaltung.org> wrote in
message news:cj**********@usenet.esken.de...
There is no such date as 2005-02-30, so you reach the next month.
Regards,
Matthias


I know, but it should increment only month (I thing so) and take maximum a
day of this month (?)
If I do this as SQL query to PostgreSQL:

SELECT TO_CHAR('YYYY-MM-DD', '2004-09-30' + interval '5 months')

then return '2005-02-28'

Month is Fabruary

--
Dawid Szalega
Jul 17 '05 #3
Dawid Szalega wrote:
"Matthias Esken" <mu******************@usenetverwaltung.org> wrote in
message news:cj**********@usenet.esken.de...
There is no such date as 2005-02-30, so you reach the next month.


I know, but it should increment only month (I thing so) and take maximum a
day of this month (?)
If I do this as SQL query to PostgreSQL:

SELECT TO_CHAR('YYYY-MM-DD', '2004-09-30' + interval '5 months')

then return '2005-02-28'


The documentation at http://www.php.net/manual/en/function.strtotime.php
leads me to the GNU date syntax at
http://www.gnu.org/software/tar/manu..._7.html#SEC115.

There, at chapter 7.6 (Relative items in date strings), you'll find the
following example:

| The fuzz in units can cause problems with relative items. For example,
| `2003-07-31 -1 month' might evaluate to 2003-07-01, because 2003-06-31
| is an invalid date. To determine the previous month more reliably, you
| can ask for the month before the 15th of the current month.

Regards,
Matthias
Jul 17 '05 #4

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

Similar topics

5
by: Dominique Javet | last post by:
Hello, I'm new to php and mysql and I use Dreamweaver MX 2004, so sorry for this "newbie" question... I've found no answer in the forum ... I've a date problem with my formular. In my mysql DB...
4
by: Fraya Pohl | last post by:
Ich want to count the days between the current day an the birthday next Year. For example (mm.dd.yyyy): Today : 07.01.2004 Birthday: 07.06.1977. How can I calculate the days to the next birthday ??...
3
by: Pjotr Wedersteers | last post by:
I'm using strtotime to get the timestamp for midnight. I have a statistics script for my pagecounter that displays hits since midnight. I also display the number of hours and minutes passed since...
1
by: peabody | last post by:
I'm trying to use the strtotime() function to manage sessions. But I get the following <?php print(time() . " - " . strtotime("+1 hour")); ?> outputs: 1097380666 - 1097308800
9
by: Google Mike | last post by:
I guess I'm confused by the whole timezone thing and I don't want to write a web app that gets this stuff wrong. I don't know how timezones work exactly -- is it just hours +/- on GMT or are there...
7
by: Rithish | last post by:
Hello. I noticed a strange thing while using strtotime() and date() functions in combination to generate from MySQL into a readable format. By default, the MySQL date field will be 0000-00-00...
6
by: Brian Kendig | last post by:
I'm working with dates in several formats including 'yyyy MMM dd', but strtotime doesn't recognize this format and returns FALSE. Is there a direct way to convert times from this format into...
5
by: Chris | last post by:
I am trying to output Monday of the current week i.e. if Monday is the 8th I want to display 'Monday 8th' for any date between Monday 8-14th. I would appreciate any help, the code below is...
9
by: Erwin Moller | last post by:
Hi group, I have been using strtotime a lot in my code. I wonder if I made a mistake in my thinking. :-/ Here follows a stripped down example. consider some dates: $date1 = "2008-02-23";...
3
oranoos3000
by: oranoos3000 | last post by:
hi i work with php and mysql on the os windows i want to using function strtotime for compute diffrences between two date , one with format date("Y-F-d") and another date is current time and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.