473,394 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DateTime

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

Jul 20 '05 #1
7 10833
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

"Eddy" <ed**@atwork4u.be> wrote in message
news:3f***********************@reader0.news.skynet .be...
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

Jul 20 '05 #2
> In the database we store this as seperate fields:
from day integer 1 to 7
from month integer 1 to 12


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
--
Jul 20 '05 #3
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...

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

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


Jul 20 '05 #4
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

John Bell wrote:
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

"Eddy" <ed**@atwork4u.be> wrote in message
news:3f***********************@reader0.news.skynet .be...
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



Jul 20 '05 #5
> 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.


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
--
Jul 20 '05 #6
In article <16********************@giganews.com>,
RE****************************@acm.org says...
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.


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


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

Jul 20 '05 #7
Hi

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

John

"Eddy" <ed**@atwork4u.be> wrote in message
news:3f***********************@reader0.news.skynet .be...
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

John Bell wrote:
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

"Eddy" <ed**@atwork4u.be> wrote in message
news:3f***********************@reader0.news.skynet .be...
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


Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Max M | last post by:
# -*- coding: latin-1 -*- """ I am currently using the datetime package, but I find that the design is oddly asymmetric. I would like to know why. Or perhaps I have misunderstood how it...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
15
by: Fritz Switzer | last post by:
I'd like to have a string assigned the value of a DateTime.AddMinutes(amount) so that the string is formatted in "HH:MM" format. For example: DateTime.Now.AddMinutes(30) returns "00:30" ...
3
by: Andrew S. Giles | last post by:
Hello, I am importing a flat text file, and putting it into a datagrid for display on a form. Currently the users have their dates and times seperated. I have two fields, therefore in the...
6
by: Ante Perkovic | last post by:
Hi, How to declare datetime object and set it to my birthday, first or last day of this month or any other date. I can't find any examples in VS.NET help! BTW, what is the difference...
5
by: I am Sam | last post by:
I have created this DateTime object and instanced it I think correctly DateTime myClubNow1=new...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
9
by: Phil B | last post by:
I am having a problem with a datetime from a web services provider The provider is sending the following SOAP response <?xml version="1.0" encoding="utf-8"?> <soap:Envelope...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.