473,405 Members | 2,282 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,405 software developers and data experts.

Diff Between 2 Dates

I am trying to find the difference between 2 dates. The problem that I am having is that all
routines in the PHP Manual and all of the scripts I have seen on the Internet only allow a date as
old as 1970. I am trying to find the age of a person in months so 1970 is not far back enough. Does
anyone know of a script where 1970 is not a restriction?

Thanks in advance.

Mike
Mar 4 '06 #1
5 1854
Mike wrote:
I am trying to find the difference between 2 dates. The problem that I am having is that all
routines in the PHP Manual and all of the scripts I have seen on the Internet only allow a date as
old as 1970. I am trying to find the age of a person in months so 1970 is not far back enough. Does
anyone know of a script where 1970 is not a restriction?

Thanks in advance.

Mike

Does the server run Linux or Windows?

--
Carl Vondrick
www.carlsoft.net
usenet [at] carlsoft [dot] net
Mar 4 '06 #2
Mike wrote:
I am trying to find the difference between 2 dates. The problem that
I am having is that all routines in the PHP Manual and all of the
scripts I have seen on the Internet only allow a date as old as 1970.
I am trying to find the age of a person in months so 1970 is not far
back enough. Does anyone know of a script where 1970 is not a
restriction?


Have a look at the calendar extension:

http://www.php.net/calendar
JW
Mar 4 '06 #3

Mike wrote:
I am trying to find the difference between 2 dates. The problem that I am having is that all
routines in the PHP Manual and all of the scripts I have seen on the Internet only allow a date as
old as 1970. I am trying to find the age of a person in months so 1970 is not far back enough. Does
anyone know of a script where 1970 is not a restriction?

Thanks in advance.

Mike


The solution is quite simple. This is how people do it in their heads.
First, substract the year the person is born from the current year.
Then, check whether the person has already celebrated his/her birthday
this year. If not--substract one.

Here's an implementation:

function age($year, $month, $day) {
$now_ts = time();
$now_a = getdate($now_ts);
$age = $now_a['year'] - $year;
$bday_ts = mktime(0, 0, 0, $month, $day, $now_a['year']);
if($now_ts < $bday_ts) {
$age--;
}
return $age;
}

Mar 4 '06 #4
Be aware this works fine for someone's age, but for more precise date
calculations, especially at much older/earlier dates, you will have to
account for all the funny time changes, corrections, and drift that
have taken place (like how they skipped a couple days completely to
make up for lost time). So i would suggest either reading up on
date/time calculations extensively or finding a good preexisting library

Mar 4 '06 #5
>I am trying to find the difference between 2 dates. The problem that I
am having is that all
routines in the PHP Manual and all of the scripts I have seen on the
Internet only allow a date as
old as 1970. I am trying to find the age of a person in months so 1970
is not far back enough. Does
anyone know of a script where 1970 is not a restriction?


PHP suffers from the limitations of a UNIX time_t. I recommend
using MySQL date functions where the allowed range includes the
years 1 thru 9999, which is good enough for most practical uses.

Gordon L. Burditt
Mar 4 '06 #6

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

Similar topics

0
by: python | last post by:
Hi- I have a lot of monthly time series data. I need to be able to compare two dates and get the number of months that they are apart. The datetime module is a daily-frequency data type. ...
8
by: TonyHa | last post by:
Hello, Does any one have using Python to write a Unix "diff" command for Window? Tony Ha.
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
4
by: PawelR | last post by:
Hello Everyone Sorry but my English is very littel. In my application I use Crystal Reports. On report I have (in one row) to dateTime. How in 3th column calculate difftime beetwen this value and...
3
by: Raghu Raman | last post by:
Hi I want to find the difference between 2 dates in terms of year.It is confusng in msdn.could u help me on that. for ex, int year=datediff("y",date1,date2)//of course it is in VB. ...
2
by: SenthilVel | last post by:
HI how to get the differences between 2 given dates?? supposse if i ahve 2 dates , DATEa, and current datetime. how can i find if the DATEa is less then 3 hrs from the current datetime ???...
4
by: Andreas Kasparek | last post by:
Hola! I'm preparing my master thesis about a XML Merge Tool implementation and was wondering if there is any open standard for XML diff regarding topics like: - is a diff result computed on...
2
by: dkrysmann | last post by:
Hi, I'm very new to this group and the php, now I've question about date function. I need function how to calculate time diffrence between two dates. First date: $rs['lastBuildDate' is like...
0
by: mariat101 | last post by:
I am collecting patient information when they do not show for an apt. I've created 4 tables linked by autonum b/c I have 3 of them in a form as subforms b/c they want to be able to see everything on...
12
Presto731
by: Presto731 | last post by:
I'm having a formulating dilemma that I hope anyone can help with. I need to do some reporting for a list of people so I can know there anniversary dates for charging them. However the way it works...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...
0
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...
0
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...

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.