U user-7256 VIP Member VIP ★ 20 ★ Impact 111 Nov 23, 2005 505 views 8 replies #1 Hey, I have date stored in this format: MM-DD-YYYY Actually I have 2, but they're different, just in the same format. I want to know the difference in DAYS between them. (e.g. 30 days apart, 20 days, are the two differences I really want...) Any help appreciated! -Matt
Hey, I have date stored in this format: MM-DD-YYYY Actually I have 2, but they're different, just in the same format. I want to know the difference in DAYS between them. (e.g. 30 days apart, 20 days, are the two differences I really want...) Any help appreciated! -Matt
iNod Eating PieVIP Member VIP ★ 20 ★ Impact 66 Nov 23, 2005 #2 Explode Method PHP: $dos = explode("-", $date); $dos2 = explode("-", $date2); $dbetween = $dos['2']-$dos2['2']; List & Split Method PHP: list($month, $day, $year) = split('[-]', $date); list($month2, $day2, $year2) = split('[-]', $date2); $dbetween = $day-$day2; iNod.
Explode Method PHP: $dos = explode("-", $date); $dos2 = explode("-", $date2); $dbetween = $dos['2']-$dos2['2']; List & Split Method PHP: list($month, $day, $year) = split('[-]', $date); list($month2, $day2, $year2) = split('[-]', $date2); $dbetween = $day-$day2; iNod.
U user-7256 VIP Member VIP ★ 20 ★ Impact 111 Nov 23, 2005 #3 That's what I thought at first, but suppose the day is 2 and the other day is 19 ... but totally different months...
That's what I thought at first, but suppose the day is 2 and the other day is 19 ... but totally different months...
Kate Domainosaurus RexTop Member VIP ★ 20 ★ Impact 21,831 Nov 23, 2005 #4 Keep it simple... Since you are extracting data from a DB (mySQL ?) use the built-in date functions. Code: SELECT DATEDIFF(start_date,end_date) as number_days http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
Keep it simple... Since you are extracting data from a DB (mySQL ?) use the built-in date functions. Code: SELECT DATEDIFF(start_date,end_date) as number_days http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
iNod Eating PieVIP Member VIP ★ 20 ★ Impact 66 Nov 23, 2005 #5 sdsinc said: Keep it simple... Since you are extracting data from a DB (mySQL ?) use the built-in date functions. Code: SELECT DATEDIFF(start_date,end_date) as number_days http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Click to expand... Oh.. Wow.. I never knew they had a built in function. I just noticed. 5.0.. Alot of hosts don't use MySql 5.0.. So that would cause some problems. iNod.
sdsinc said: Keep it simple... Since you are extracting data from a DB (mySQL ?) use the built-in date functions. Code: SELECT DATEDIFF(start_date,end_date) as number_days http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Click to expand... Oh.. Wow.. I never knew they had a built in function. I just noticed. 5.0.. Alot of hosts don't use MySql 5.0.. So that would cause some problems. iNod.
Kate Domainosaurus RexTop Member VIP ★ 20 ★ Impact 21,831 Nov 23, 2005 #6 I believe DATEDIFF is available in MySQL 4.1.1 and above. If you are unsure which version you are running check with this command: Code: SELECT VERSION()
I believe DATEDIFF is available in MySQL 4.1.1 and above. If you are unsure which version you are running check with this command: Code: SELECT VERSION()
U user-7256 VIP Member VIP ★ 20 ★ Impact 111 Nov 23, 2005 #7 SDS - can you CONFIRM that I can use that function with 4.1.1? If so and it works I'll hand over some NP$.
SDS - can you CONFIRM that I can use that function with 4.1.1? If so and it works I'll hand over some NP$.
iNod Eating PieVIP Member VIP ★ 20 ★ Impact 66 Nov 23, 2005 #8 compuXP said: SDS - can you CONFIRM that I can use that function with 4.1.1? If so and it works I'll hand over some NP$. Click to expand... DATEDIFF is in mysql versions 4.1 and up. As said here. http://www.mysqlfreaks.com/statements/56.php iNod.
compuXP said: SDS - can you CONFIRM that I can use that function with 4.1.1? If so and it works I'll hand over some NP$. Click to expand... DATEDIFF is in mysql versions 4.1 and up. As said here. http://www.mysqlfreaks.com/statements/56.php iNod.
E eagle12 Established Member ★ 20 ★ Impact 8 Nov 23, 2005 #9 PHP method: PHP: <? $t = explode("-","08-28-1979"); $date1 = strtotime($t[2].'-'.$t[1].'-'.$t[0]); $t = explode("-","08-28-1980"); $date2 = strtotime($t[2].'-'.$t[1].'-'.$t[0]); $diff = ($date2-$date1)/86400; ?>
PHP method: PHP: <? $t = explode("-","08-28-1979"); $date1 = strtotime($t[2].'-'.$t[1].'-'.$t[0]); $t = explode("-","08-28-1980"); $date2 = strtotime($t[2].'-'.$t[1].'-'.$t[0]); $diff = ($date2-$date1)/86400; ?>