473,394 Members | 1,802 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,394 software developers and data experts.

subtract 1 day

I can't see what I'm doing wrong. I'm subtracting 60*60*24 from a unix
time stamp and the result is 23 hours earlier, not 24.
Start with a unix time stamp:

$unixtime=1144018006;

convert it to a date:
$date=getdate($unixtime);
date Array
(
[seconds] => 46
[minutes] => 46
[hours] => 17
[mday] => 2
[wday] => 0
[mon] => 4
[year] => 2006
[yday] => 91
[weekday] => Sunday
[month] => April
[0] => 1144018006
)
date
subtract 1 day:
$gobackseconds=60*60*24 ;
$unixtime2=$unixtime-$gobackseconds;

and see what time it is:
$date2=getdate($unixtime2);
date2 Array
(
[seconds] => 46
[minutes] => 46
[hours] => 16
[mday] => 1
[wday] => 6
[mon] => 4
[year] => 2006
[yday] => 90
[weekday] => Saturday
[month] => April
[0] => 1143931606
)
date2

Notice that in the first date, there are 17 hours, and in the second
date there are 16 hours. Arrrrrrg. What is the problem ?
Apr 3 '06 #1
4 16686
On Mon, 03 Apr 2006 08:06:55 +0000, meltedown wrote:
I can't see what I'm doing wrong. I'm subtracting 60*60*24 from a unix
time stamp and the result is 23 hours earlier, not 24. Start with a unix
time stamp:


Try doing this instead:

$unixtime2 = strtotime("-1 day", $unixtime);

I couldn't see what you were doing wrong in your code from a quick glance,
but the above way is easier to read anyway.

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Apr 3 '06 #2
Andy Jeffries wrote:
On Mon, 03 Apr 2006 08:06:55 +0000, meltedown wrote:
I can't see what I'm doing wrong. I'm subtracting 60*60*24 from a unix
time stamp and the result is 23 hours earlier, not 24. Start with a unix
time stamp:


Try doing this instead:

$unixtime2 = strtotime("-1 day", $unixtime);

I couldn't see what you were doing wrong in your code from a quick glance,
but the above way is easier to read anyway.

Cheers,
Andy

Thanks that really helped a lot, five minutes to fix what I've been
banging my head against all night. Funny thing is that code worked fine
for a year and it still works for most dates but it hit that one date
and didn't work right.
Apr 3 '06 #3
On Mon, 03 Apr 2006 08:59:19 +0000, meltedown wrote:
Try doing this instead:

$unixtime2 = strtotime("-1 day", $unixtime);

I couldn't see what you were doing wrong in your code from a quick
glance, but the above way is easier to read anyway.
Thanks that really helped a lot, five minutes to fix what I've been
banging my head against all night.


It's always the way with coding.... Glad I could help.
Funny thing is that code worked fine
for a year and it still works for most dates but it hit that one date and
didn't work right.


It's very odd. I've had another quick glance at your code and still can't
see anything obviously wrong. Never mind, you've got a solution now.

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Apr 3 '06 #4
"meltedown" <gr*****@reenie.org> wrote in message
news:Gt********************@fe08.news.easynews.com ...
Andy Jeffries wrote:
On Mon, 03 Apr 2006 08:06:55 +0000, meltedown wrote:
I can't see what I'm doing wrong. I'm subtracting 60*60*24 from a unix
time stamp and the result is 23 hours earlier, not 24. Start with a unix
time stamp:


Try doing this instead:

$unixtime2 = strtotime("-1 day", $unixtime);

I couldn't see what you were doing wrong in your code from a quick
glance,
but the above way is easier to read anyway.

Cheers,
Andy

Thanks that really helped a lot, five minutes to fix what I've been
banging my head against all night. Funny thing is that code worked fine
for a year and it still works for most dates but it hit that one date and
didn't work right.


I had the same effect when clocks were turned +1 hour to daylight saving
time on March 26th here in Finland. I had two dates of which one was in
normal time and another that was in daylight saving time and I kept
wondering why the difference between them is was 5 days and 23 hours or
something like that, until the whole daylight saving thing finally dawned to
me. I fixed it by using GMT times which are not affected by DST.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Apr 3 '06 #5

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

Similar topics

8
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month"...
7
by: Jimbo | last post by:
Anyone know how I can subtract 12 months from the current date?
4
by: Lee | last post by:
Hi All, I have a datetime field and want to subtract 24 (or any other number of) hours from it. How would I go about this? Thanks Lee
3
by: ReidarT | last post by:
I have a javascript where I try to add 1 to a value through a button and show the value in a textbox and subtract 1 from another button and show the result in the same textfield. This seems to...
10
by: Trapulo | last post by:
Why Now.Date.Subtract(New Date(2000, 1, 1)).Days returns 731529?? It is a too big value a think! I aspect something as 1030-1100....
5
by: Sandy | last post by:
Hello I need to subtract a pm time from an am time, e.g. 10:00 a.m. from 1:00 p.m. to get 3 I have two textboxes for the time values and next to each is a dropdownlist to click indicating a.m....
3
by: S. van Beek | last post by:
Dear reader, With DatePart() you can subtract the year or the week from a date field with: DatePart("yyyy";) for the year
5
by: cvisal | last post by:
Hi all Im working on productivity calculations (Time calculations) and need some help in coding. Database Tool:MS-Access 2003. The general operator punch-in time is 5:30 AM and the punch-out...
8
by: gavinstone007 | last post by:
Who can solve this? Wrte a class number which represents all numbers. Implement member functions to carry out the following arithmetic operations on class instances, add- which returns an object...
8
by: Remington | last post by:
I am using windows 2000pro with access 2000. I am trying to make a database for our HR department, that would allow our HR Director to type in an employee's ID number into a form and then select...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.