[Log In ] [New Posts] []
Go Back   GotApex? Forums Forums > General Topics > Software, OS, and the Internet
User Name
Password

Reply
 
Thread Tools Search this Thread Display Modes
Old 10-25-2002, 01:50 PM   #1
mcs328
Admiral
 
mcs328's Avatar
 
Join Date: Feb 2001
Location: Maryland
Posts: 6,578
SQL Question: Date subtraction

How would you write a SQL statement to return rows between a specific date and that same date minus a user entered number of days.

So I wanted records from 12/25/2001 and 45 days prior. The date and the number of days is user entered.

Just thought I throw this question in here and then start hunting for answers elsewhere. It'll be good warm up brain exercises for those in the know
__________________
mcs328 is offline   Reply With Quote
Old 11-03-2002, 11:35 AM   #2
wga22
Lieutenant
 
Join Date: May 2000
Location: Vienna, VA
Posts: 212
Send a message via AIM to wga22 Send a message via Yahoo to wga22
often you can convert the time to an integer, which represents the number of milliseconds since a given system date, such as 1-1-1970. Subtract 45 * 24 * 36000 from this number and you will have the number of milliseconds from 1970 of your new date. Convert this number back to a date.

Otherwise you will be challenged by crossing over months/years/leap years. Java and Javascript both have a date object that would let you do this programmatically, so if your database wont do it, maybe a stored procedure will, or you can write a program.

javascript: http://www.w3schools.com/js/js_datetime.asp see getTime()

Java: http://java.sun.com/products/jdk/1.1...util.Date.html

http://javascript.miningco.com/libra...bldatemath.htm
wga22 is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump


All times are GMT -7. The time now is 04:43 PM.