What's a good way to calculate the number of days between two dates in
the following format:
2003-07-15
2003-08-02
I've looked at the PHP date functions but I'm still a bit lost... 6 9045
Yeah, I follow that - but I end up with a unix epoch date - how can I
determine how many days diff that represents? In other words, per
your suggestion I can get date1 and date2 and determine via mktime the
diff - but I still need to know how many days diff that is???
On Sun, 03 Aug 2003 03:18:26 GMT, Blaine HIlton
<bl************ ***@verizon.net > wrote: What you need to do is check the mktime() function at http://www.php.net/manual/en/function.mktime.php.
Basiclly you would use mktime and send the function the date and call that date1 and then another mktime and call that date2. Then just subtract. mktime() will give you the unix epoch date.
Also for a good example check out http://www.befriend.com/code_gallery..._elapsed_time/, however there are I believe 2 errors where a division sign should be a multiplication .
Mine looks like:
//$divider['months'] = ( 60 * 60 * 24 * 365 / 12 ); $divider['months'] = ( 60 * 60 * 24 * 365 * 12 ); // cheanged this one too // $divider['weeks'] = ( 60 * 60 * 24 / 7 ); $divider['weeks'] = ( 60 * 60 * 24 * 7 ); // I changed / to *
and can be seen in action at http://www.webcalc.net/calc/0529.php.
I would say first check out the 3 links that I gave: http://www.php.net/manual/en/function.mktime.php http://www.befriend.com/code_gallery..._elapsed_time/ http://www.webcalc.net/calc/0529.php
If you read through there you will have it working. Once you have the
time from epoch for each date you subtract. That gives you the
seconds, then times by 60 for minutes, then 60 more for hours then 24
for days.
--
Blaine Hilton http://www.webcalc.net/
On Sun, 03 Aug 2003 06:00:32 GMT, Ralph Freshour <ra***@primemai l.com>
wrote: Yeah, I follow that - but I end up with a unix epoch date - how can I determine how many days diff that represents? In other words, per your suggestion I can get date1 and date2 and determine via mktime the diff - but I still need to know how many days diff that is??? On Sun, 03 Aug 2003 03:18:26 GMT, Blaine HIlton <bl*********** ****@verizon.ne t> wrote:
What you need to do is check the mktime() function at http://www.php.net/manual/en/function.mktime.php.
Basiclly you would use mktime and send the function the date and call that date1 and then another mktime and call that date2. Then just subtract. mktime() will give you the unix epoch date.
Also for a good example check out http://www.befriend.com/code_gallery..._elapsed_time/, however there are I believe 2 errors where a division sign should be a multiplicatio n.
Mine looks like:
//$divider['months'] = ( 60 * 60 * 24 * 365 / 12 ); $divider['months'] = ( 60 * 60 * 24 * 365 * 12 ); // cheanged this one too // $divider['weeks'] = ( 60 * 60 * 24 / 7 ); $divider['weeks'] = ( 60 * 60 * 24 * 7 ); // I changed / to *
and can be seen in action at http://www.webcalc.net/calc/0529.php.
I did check out the links you gave me - I understand the epoch number
now - but when I do the math to get the number of days difference I
get a huge number:
// get todays date
$now = time();
print "<br>now: $now";
$then = mktime(0,0,0,8, 15,2003);
print "<br>then: $then";
$diff = $now - $then;
print "<br>diff: $diff";
$min = $diff * 60;
print "<br>min: $min";
$hours = $min * 60;
print "<br>hours: $hours";
$days = $hours * 24;
print "<br>days: $days";
$days is a huge number and there is not that many days diff between
time() and august 15, 2003 - what am I not understanding here?
On Sun, 03 Aug 2003 07:23:52 GMT, Blaine HIlton
<bl************ ***@verizon.net > wrote: I would say first check out the 3 links that I gave:
http://www.php.net/manual/en/function.mktime.php http://www.befriend.com/code_gallery..._elapsed_time/ http://www.webcalc.net/calc/0529.php
If you read through there you will have it working. Once you have the time from epoch for each date you subtract. That gives you the seconds, then times by 60 for minutes, then 60 more for hours then 24 for days.
Ralph Freshour wrote: I did check out the links you gave me - I understand the epoch number now - but when I do the math to get the number of days difference I get a huge number:
// get todays date $now = time(); print "<br>now: $now"; $then = mktime(0,0,0,8, 15,2003); print "<br>then: $then"; $diff = $now - $then; print "<br>diff: $diff"; $min = $diff * 60; print "<br>min: $min"; $hours = $min * 60; print "<br>hours: $hours"; $days = $hours * 24; print "<br>days: $days";
$days is a huge number and there is not that many days diff between time() and august 15, 2003 - what am I not understanding here?
What you're not understanding is the fact that his math was wrong ;) If
you've got 60 seconds in a minute, then there are 60 / 60 = 1 minute in
a minute, not 60 * 60 = 3600 minutes in a minute. Change all those * to
/ and it should work.
Yes sorry about that / is a big difference then ;-)
--
Blaine
On Sun, 03 Aug 2003 10:35:48 -0400, Joshua Ghiloni
<jd***@SPAM.ME. AND.DIE.cwru.ed u> wrote: Ralph Freshour wrote: I did check out the links you gave me - I understand the epoch number now - but when I do the math to get the number of days difference I get a huge number:
// get todays date $now = time(); print "<br>now: $now"; $then = mktime(0,0,0,8, 15,2003); print "<br>then: $then"; $diff = $now - $then; print "<br>diff: $diff"; $min = $diff * 60; print "<br>min: $min"; $hours = $min * 60; print "<br>hours: $hours"; $days = $hours * 24; print "<br>days: $days";
$days is a huge number and there is not that many days diff between time() and august 15, 2003 - what am I not understanding here? What you're not understanding is the fact that his math was wrong ;) If you've got 60 seconds in a minute, then there are 60 / 60 = 1 minute in a minute, not 60 * 60 = 3600 minutes in a minute. Change all those * to / and it should work. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ron Adam |
last post by:
Hi, I'm having fun learning Python and want to say thanks to everyone
here for a great programming language.
Below is my first Python program (not my first program) and I'd
apreciate any feedback on how I might do things differently to make it
either more consice, readable, or faster. ie... are there better ways
to do it in Python?
It won't break any records for calculating pi, that wasn't my goal,
learning Python was. But it might...
|
by: riki |
last post by:
hello,
i need to calculate num of days between 2 dates...
i get separate parts of dates from html form, then i need to "make" begining
and ending date and calculate difference between them...
something like this, in sybase:
DAYS(YMD(?YEAR?,?MONTH?,?DAY?), YMD(?YEAR1?,?MONTH1?,?DAY1?))
thnx
|
by: Anthony Robinson |
last post by:
Is anyone aware of a function (system or user defined) that will
calculate business days? For instance: I have a column in as table
called DATE. I want to be able to add five business days to that date
and come up with a new date. Is that possible.
Also, is there anyway that DB2 can be aware of holidays? Maybe load
them onto the server in some type of reference file or something.
I ask these questions because I'm working on a banking...
|
by: Tony Williams |
last post by:
I have a table with two fields, txtvalue (a number field) and txtmonth ( a
date/time field). I want to create a report that shows the difference in
value between the value in txtvalue in one value of txtmonth and the value
of txtvalue in another value of txtmonth and the percentage increase . For
example if I have the value 1000 in 30/03/03 and the value 1100 in 30/03/04
How do I calculate the difference as 100 and the increase as 10%. I...
|
by: pauly |
last post by:
Hello All,
I have been trying to create a query that extracts data from a table
and calculates the elapsed time between records. The table called
"Imported_table". I need to be able to calculate the difference in
dates when the vin and labourop are the same and not show any other
records except for these and add a new field called days elapsed and
odom elapsed. Refer to rough sample data below. Anyhelp would be
greatly apreciated.
VIN ...
| |
by: b.beeching |
last post by:
Not sure if my subject is entirely accurate but here goes.
I need to calculate the date difference between a date A and a date
B... however date B relies entily on date A.
EG: i have an advert in a paper (The Daily Telegraph say), now i need
to know the next and previos dates that this occured.
I can do this very easily for a one time calculations, however i need
to do this for many 000's of rows.
|
by: krishnakant Mane |
last post by:
hello,
I am strangely confused with a date calculation problem.
the point is that I want to calculate difference in two dates in days.
there are two aspects to this problem.
firstly, I can't get a way to convert a string like "1/2/2005" in a
genuan date object which is needed for calculation.
now once this is done I will create a another date object with
today = datetime.datetime.now()
and then see the difference between this today and...
|
by: rodneyeid |
last post by:
Hi,
I have an attendance machine which saves records in an Access Database in the following format : UserID DATE/TIME Checktype
where if checktype is 0 then its check in and if it is 1 then it check out
I need to calculate number of hours for each userID /day.
I.e UserID =1 DATE/Time= 11/12/2007 12:36 P.M CheckType=0
UserID = 1 DATE/Time= 11/12/2007 17:36 P.M CheckType=1
i am counting the day as being from 12:00 am till...
|
by: cbalian |
last post by:
I am looking for a TSQL code that would calculate a specific date each month that varies based on the following condition:
I need the result that would return the date of the Thursday after the Last Wednesday of each month.
I'm guessing a code that would be (Last Wednesday of Month) + 1 Day.
My problem is I can find ways to calculate a day within a week, the last day or first day of a month, add/subtract as needed from that. But...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |