Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date comparisons

Status
Not open for further replies.
May 22, 2002
63
GB
Hi,

Can anyone tell me how i can get mySQL to tell me how many days there are between two dates stored in a mysql database?

cheers,

Anders
 
If each row of the table has a column "begin" and a column "end", then the query:

SELECT sec_to_time(time_to_sec(end) - time_to_sec(begin)) from table

will return something in the format "Days:Hours:Minutes" between them. You can then use your scripting language (which I know from your cross-post is PHP, please don't do that any more) to convert that do days for display. ______________________________________________________________________
TANSTAAFL!
 
Hmmm that's a bit much, there's more convenient way:

SELECT TO_DAYS(end) - TO_DAYS(start) FROM table

That gives the number of days without any need for scripting


Cheers,

Bromrrrr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top