Jump to content

Determine how long between dates


sotusotusotu

Recommended Posts

Hi guys,

 

I have a datetime field in my database which stores a datetime value.  I basically need to find if it has been exactly a week after the entry.  Retreiving this data is not the problem as I have done this with SQL.  My issue is trying to find out if the 7 interval query is actually greater than the original query by more than 7 days. For example if the original value is: 2009-05-03 22:07:59 and the +7 Day interval is: 2009-05-10 22:07:59, how can I find out if the second is great by 7 days?

 

Can anyone please give me an example of how to do this, or point me in the right diffection?

 

Cheers

Link to comment
Share on other sites

Hi Ken2K7,

 

Sotusotusotu doesn't mean anything. I think originally it started as 'sotu' when opening up a an email account many moons ago; then as passwords were forgotten, extra sotu's where added to the end.

 

Cheers for you suggestions but I just having just tried the datediff function, it didn't seem to calculate the difference between the days/hours correctly.  For example if you try exactly -7 days difference:

 

SELECT DATEDIFF( '2009-04-26 22:07:59', '2009-05-03 22:07:59' )

FROM `letters` AS DiffDate

 

The result is -7days.

 

However if you just change the time values in the 2nd datetime value to a couple of hours earlier, which should be the previous day, I still '-7days' as the result.  Surely this is incorrect and should return -6 days?!

 

For example:

 

SELECT DATEDIFF( '2009-04-26 22:07:59', '2009-05-03 20:07:59' )

FROM `letters` AS DiffDate

 

Any other suggestions?

Link to comment
Share on other sites

What you are saying is completely true Ken. Thank you for pointing that my reply was completely stupid  :P

 

It's after 1 in the morning here so I think I might put down the computer and stop asking silly questions and leave this for the night.

 

Cheers for the help mate.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.