PHP day difference calculation problem, occur on diff. month

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
d0rr
Forum Newbie
Posts: 2
Joined: Wed Mar 31, 2004 8:32 pm

PHP day difference calculation problem, occur on diff. month

Post by d0rr »

guys, i need some help on PHP day difference calculation..

i have my date format as in YYYYMMDD, for instance 1st april 2004 = 20040401

it works fine if it is within the same month.. for instance:
20040310 - 20040305 = 5 days gap.. (since i am using simple subtractive code)

however, when it comes to different month, it tends to mix up:
20040430 - 20040330 = 100 days gap!! (suppose to be 1 month, 30 days!)

anyone can help me solve this problem? it's kinda urgent~ :? :?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Store your date as the unix epoch time, then subtract the two dates, and your left with the number of seconds between the two dates to do what you like with.
Post Reply