How can i use a time/date stamp to work out the difference in years between two stamps. The normal getdate functions counts from 1970, but i need to include dates before 1970
thanks
Muzz
time/date stamp
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
yes there are other calculations to consider too, the main ones are, how days ago the user last logged in (not necessarily in the same month or year), the age of the person depending upon the date of birth and the current date.
For these a timestamp seems the easiest option because it allows calculations to be treated as any other integer calculation.
So .. if i need dates before 1970 would i have to dump the timestamp and store day month and year seperate?
For these a timestamp seems the easiest option because it allows calculations to be treated as any other integer calculation.
So .. if i need dates before 1970 would i have to dump the timestamp and store day month and year seperate?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
For calculating last login times a timestamp would be most appropriate because it's pretty much impossible for them to have last logged in in 1969.
For calculating the age of someone you could do something like this which uses the year inputted to get a rough age and then checks using timestamps that the day has passed and if not subtracts one from the rough age:
Having never had to work with older dates before I've just kinda come up with this off the top of my head, someone else may know of a function that can do this that I've missed.
Mac
For calculating the age of someone you could do something like this which uses the year inputted to get a rough age and then checks using timestamps that the day has passed and if not subtracts one from the rough age:
Code: Select all
<?php
$age = date('Y') - $_POST['yearborn'];
$agets = mktime(0, 0, 0, $_POST['monthborn'], $_POST['dayborn']);
$datedif = mktime() - $agets;
if ($datedif < 0) {
--$age;
}
echo $age;
?>Mac