dearmoawiz Posted May 9, 2008 Share Posted May 9, 2008 hi guyz .. hwz u all i need ur help here is the scenario........ i hav today date with date function n i have another date which is save in database like 09/05/2008 (today date) and 12/04/2008 (date from database) now i want to calculate the difference b/w these 2 dates in the form of days then how i calculate that plz help me wizzz!!!! Quote Link to comment Share on other sites More sharing options...
Barand Posted May 9, 2008 Share Posted May 9, 2008 If you want to process dates, store them in ISO (YYYY-MM-DD) format in a DATE type column. Then you can SELECT DATEDIFF(CURDATE(), mydatecol ) as totaldays FROM .... Quote Link to comment Share on other sites More sharing options...
dearmoawiz Posted May 9, 2008 Author Share Posted May 9, 2008 this way is not suitable for me bcoz my requirements are bit different then this one i just want to calculate the differete b/w days and month like 12/04 and 14/05 got it ? Quote Link to comment Share on other sites More sharing options...
Barand Posted May 9, 2008 Share Posted May 9, 2008 You should store dates for functionality, not appearance. You can format on output to any format you want. Got it? But, if you insist on a non-processable format that's as much use in a database as a chocolate teapot, then Get date from database Convert your d/m/y date to ISO Now you can use strtotime() to convert to to unix timestamp. Subtract from the the current time() value to get the difference in seconds Divide that difference by 86400 to get days. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.