Hello everybody,
i have 2 dates in my database
dateStart and dateEnd both stored as as type date: y-m-d (eg 2003-05-05)
how can i get years.
Thanking You
Megha
Hello everybody,
i have 2 dates in my database
dateStart and dateEnd both stored as as type date: y-m-d (eg 2003-05-05)
how can i get years.
Thanking You
Megha
One option:
http://php.net/manual/en/function.mktime.php
Another would be to use$date = explode('-',$date)on both (with different variable names of course) then just use $date[0] to get the year from each, then subtract. That assumes exactly equivalent formats all of the time.
The first option will allow you a little more precision (even including months and days) and to know how much time or how many calendar years have passed; the second will only allow you to consider calendar years. (So Dec 31-Jan 1 = 1 year; Jan 1-Dec 31 = 0 years. Is that correct?)
Daniel - Freelance Web Design | <?php?> | <html>| Deutsch | italiano | español | português | català | un peu de français | Ninasoma Kiswahili | 日本語の学生でした。| درست العربية
check out the DateTime class as well.
Adrian ~ facebook | gist/github
['66.215.156.37','208.75.149.97'] // ip,ip array!
"Take that sticker *off* your hat; you look stupid" --Wil Wheaton
Or
PHP Code:echo date("Y", strtotime($row['dateStart']));
Resolved Get Year Duration .
Thank you all for your quick feedback. I got a problem to get the total years. After that this is solved.
At first the datediff() function gives the days. And then by dividing it by 365 it returns the years
e.g.
sum(datediff( `Date1` , `Date2` ) ) AS totalDays // this gives total days
sum( datediff( `Date1` , `Date2` ) ) /365 AS totalYears // this gives total years
Bookmarks