dbTalk Databases Forums  

return number of days between two dates.

comp.databases comp.databases


Discuss return number of days between two dates. in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sorensong@gmail.com
 
Posts: n/a

Default return number of days between two dates. - 03-02-2007 , 01:19 PM






I've been trying all morning to figure out a way to display the
number
of days/months between CURDATE() and a future date (myqsl column).
I've tried BETWEEN and something like this:

SUBDATE(CURDATE(), MAX(stopdate) AND NOW()) AS time_left


I guess trick is converting a date format to a number format. I don't
know, I'm lost!


Any guidance in the right direction would be GREATLY appreciated.
Thanks a lot.


Reply With Quote
  #2  
Old   
Bill Karwin
 
Posts: n/a

Default Re: return number of days between two dates. - 03-04-2007 , 09:04 PM






On Mar 2, 11:19 am, sorens... (AT) gmail (DOT) com wrote:
Quote:
I guess trick is converting a date format to a number format. I don't
know, I'm lost!
Read about the TO_DAYS() function here:
http://dev.mysql.com/doc/refman/5.0/...functions.html

Regards,
Bill K.



Reply With Quote
  #3  
Old   
yiata
 
Posts: n/a

Default Re: return number of days between two dates. - 03-07-2007 , 02:49 PM



On Mar 2, 2:19 pm, sorens... (AT) gmail (DOT) com wrote:
Quote:
I've been trying all morning to figure out a way to display the
number
of days/months between CURDATE() and a future date (myqsl column).
I've tried BETWEEN and something like this:

SUBDATE(CURDATE(), MAX(stopdate) AND NOW()) AS time_left

I guess trick is converting a date format to a number format. I don't
know, I'm lost!

Any guidance in the right direction would be GREATLY appreciated.
Thanks a lot.
You're probably looking for these functions:

DATEDIFF()
Returns expr1 - expr2 expressed as a value in days from one date to
the other. expr1 and expr2 are date or date-and-time expressions. Only
the date parts of the values are used in the calculation

PERIOD_DIFF(P1,P2)
Returns the number of months between periods P1 and P2. P1 and P2
should be in the format YYMM or YYYYMM. Note that the period arguments
P1 and P2 are not date values.

-Tri



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.