473,836 Members | 1,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=11440 18006;

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=$uni xtime-$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 16716
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******** ************@fe 08.news.easynew s.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***@bhg byrzcv.arg)
Apr 3 '06 #5

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

Similar topics

8
25393
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" size=3> Month: <input name="m1" alt="Month" size=3> Year: <input name="y1" alt="Year" size=5> (4 digits for year, e.g.
7
24624
by: Jimbo | last post by:
Anyone know how I can subtract 12 months from the current date?
4
21038
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
5977
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 work with subtraction but the addition just treats it like a string . If the value is in the label is 22 and I press the Add-button, I get 2222. When I click the subtract button I get 2221 (the correct value) <script language="javascript"...
10
2514
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
2764
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. or p.m Any help will be greatly appreciated Sandy
3
9872
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
6521
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 time is 2:00PM. The Break times are 1) 9:30 AM to 9:45 AM 2) 11:00AM to 11:30 AM 3) 12:30PM to 12:45 PM
8
4136
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 of class number whose value is the sum of the numbers added, subtract- returns an object of class number and value is the result subtracting the second number object from the first, multiply and divide (the return formats are the same as for add...
8
12831
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 the dates the employee took off from work. (I have the calander add-in 8.0 setup to easily select the dates already) There are two Date Fields, "Leave Date", and "Return Date" where the calander selections are stored. They are in the 12/25/2006...
0
9814
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
9666
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
10543
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...
1
10585
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7786
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
6976
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();...
1
4447
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4009
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
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.