473,762 Members | 7,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2237
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************ ******@usenetve rwaltung.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************ ******@usenetve rwaltung.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
3735
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 my filed "date" in table "experience" is like this: Y-m-d (2002-07-23). My fied`date` is date, NOT NULL with no default entry My form read well the date data depending the id, (pe. 30.02.2003), but when I submit a new date, I receive as result...
4
1622
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 ?? Please help me !! Thanks Fraya Pohl
3
4659
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 midnight. $start = strtotime ('today 00:00'); $timepassed = date ('H:i', time () - $start); The weird part is at 11.30 AM it says 12 hrs and 30 minutes have passed. I tried adding GMT+1 like so: $start = strtotime ('today 00:00 GMT+1');...
1
2168
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
2133
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 going to be minor differences on minutes and seconds too? What I want to do is have a web app that one logs into (great place for submitting the browser's view on time via Javascript) and then the user sees the records from the database with...
7
5373
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 00:00:00 When I pass this to strtotime() to generate the timestamp, and then pass it to the date function, it generates 30-11-1999. <? print ( "<br> strtotime for '0000-00-00 00:00:00' : " . strtotime (
6
1533
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 timestamps, other than my having to whip up a simple parsing routine? My headache is that I use strtotime in a lot of places in a lot of files, and I'd hate to have to add a wrapper everyplace I use it. I wish there were a way to extend strtotime's...
5
13719
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 heading in the right direction but doesn't quite give me the results I am looking for. $givenday = mktime(0,0,0,10,08,2007); $Monday = strtotime("Monday this week",$givenday); echo date("j M Y H:i:s", $Monday);
9
1828
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"; $date2 = "2008-02-23"; (They are the same)
3
9692
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 query is $sql_select="select * from $table_name where confirm=1 and "; $sql_select.=strtotime."(".expire_date_show.") - ".time().">=0"; //expire_date_show is the column in database with format date("Y-F-d")
0
9554
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
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
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
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
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
7358
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
5266
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2788
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.