all groups > sql server (alternate) > october 2003 >
You're in the

sql server (alternate)

group:

DateTime


Re: DateTime Guinness Mann
10/6/2003 12:38:37 PM
sql server (alternate):
In article <16mdnUmGHswBIRyiRVn-vg@giganews.com>,
REMOVE_BEFORE_REPLYING_dportas@acm.org says...
[quoted text, click to view]

I would think that it would be important to have a year because
depending on the year, the difference between two identical dates can
differ.

-- Rick
Re: DateTime John Bell
10/6/2003 5:47:29 PM
Hi

You could try something like:

DECLARE @baseDate datetime
SET @baseDate = '20021231'

SELECT *
FROM Tours
WHERE getdate() BETWEEN dateadd(Month, [From Month], dateadd ( day, [From
Day], @baseDate ) )
AND dateadd(Month, [To Month], dateadd ( day, [To Day], @baseDate ) )

John

[quoted text, click to view]

Re: DateTime David Portas
10/6/2003 5:56:44 PM
[quoted text, click to view]

Why? Not a very effective way to store dates when you have a proper DATETIME
datatype to do the job. Change your columns to DATETIME.

If you want to ignore the year then just put a dummy year number on your
dates:

CREATE TABLE Sometable (fromdate DATETIME NOT NULL, todate DATETIME, PRIMARY
KEY (fromdate), CHECK (fromdate<todate))
INSERT INTO Sometable VALUES ('19001101','19010401')

Then do the query like this:

DECLARE @some_date DATETIME
SET @some_date = CURRENT_TIMESTAMP

SELECT *
FROM Sometable
WHERE DATEADD(YEAR,YEAR(fromdate)-YEAR(@some_date),@some_date) BETWEEN
fromdate AND todate
OR DATEADD(YEAR,YEAR(fromdate)-YEAR(@some_date)+1,@some_date) BETWEEN
fromdate AND todate

Of course, if the year is relevant you can just do:

SELECT *
FROM Sometable
WHERE @some_date BETWEEN fromdate AND todate

--
David Portas
------------
Please reply only to the newsgroup
--

DateTime Eddy
10/6/2003 6:33:29 PM
I have to check whether a given date is between a day and a month.
A guided tour is only scheduled from november 1st until april 1st.
when i want to make a reservation for the tour Today the query should
tell me that today is out of range.

In the database we store this as seperate fields:
from day integer 1 to 7
from month integer 1 to 12

till day integer 1 to 7
till month integer 1 to 12

when Today is between november 1st and march 30 then NoGood
when Today is not between november 1st and march 30 then Proceed

I have tried a number of variations but without any results yet.
I hope someone can give a tip on how to solve this particular case
Many thanks in advance
eddy
Re: DateTime Eddy
10/6/2003 7:31:02 PM
Thanks for the tip...
I have considered datetime fields a while ago...
It is more or less working adding a dummy year into the equation...
but i'll reconsider.
Having a year means the users will have to add a record for the coming
years. But it could prove to be more flexible this way.
Anyway thanks for the help...

[quoted text, click to view]
Re: DateTime Eddy
10/6/2003 7:35:10 PM
Hi,
thanks for the reply.
need to think this through though ... what date is @BaseDate

getdate() could be about any date the user choses

thanks
eddy galle

[quoted text, click to view]
Re: DateTime David Portas
10/6/2003 8:05:53 PM
[quoted text, click to view]

Have another look at my example. You don't have to do this - the query works
without it.

--
David Portas
------------
Please reply only to the newsgroup
--

Re: DateTime John Bell
10/8/2003 11:30:15 PM
Hi

Basedate is the date that you used to get the offset for your month and year
columns.

John

[quoted text, click to view]

AddThis Social Bookmark Button