472,977 Members | 2,067 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Select date in british format

I am able to extract dates in the correct format i.e.

SELECT CONVERT(VARCHAR(8), GETDATE(), 3)
=dd/mm/yy

My issue is that my users are selecting a date in this format and I
need to select data based on this range.

i.e.

SELECT * FROM TABLE
WHERE date BETWEEN '01/11/2007' AND '30/11/2007'
=The conversion of a char data type to a datetime data type resulted
in an out-of-range datetime value.
(Obviously expecting to see mm/dd/yyyy)

Next Try:
SELECT * FROM TABLE
WHERE CONVERT(VARCHAR(8), date, 3) BETWEEN '01/11/07' AND '30/11/07'
=Returns rows outside of required range

What do I need to do to select all data in my table where the data
range is between 01/11/07 AND 30/11/07 in this format dd/mm/yy ???
Jun 27 '08 #1
2 3836
<sh***********@hotmail.comwrote in message
news:ac**********************************@r9g2000p rd.googlegroups.com...
>I am able to extract dates in the correct format i.e.

SELECT CONVERT(VARCHAR(8), GETDATE(), 3)
=dd/mm/yy

My issue is that my users are selecting a date in this format and I
need to select data based on this range.

i.e.

SELECT * FROM TABLE
WHERE date BETWEEN '01/11/2007' AND '30/11/2007'
=The conversion of a char data type to a datetime data type resulted
in an out-of-range datetime value.
(Obviously expecting to see mm/dd/yyyy)

Next Try:
SELECT * FROM TABLE
WHERE CONVERT(VARCHAR(8), date, 3) BETWEEN '01/11/07' AND '30/11/07'
=Returns rows outside of required range

What do I need to do to select all data in my table where the data
range is between 01/11/07 AND 30/11/07 in this format dd/mm/yy ???

I assume these are DATETIMEs? DATETIMEs don't have any format in SQL Server.

After validating the users input, your client application should query the
database using DATETIME or SMALLDATETIME types (which don't have any
format).

Your queries therefore ought to look something like:

BETWEEN @dt1 AND @dt2

where @dt1 and @dt2 are DATETIME or SMALLDATETIME types.

In fact it is better to use >= and < rather than BETWEEN. DATETIME values
always contain both date and time elements. If you use BETWEEN then any
times after midnight on the last day of the period will be excluded.

--
David Portas



Jun 27 '08 #2
Figured it out.

SELECT * FROM TABLE
WHERE date BETWEEN CONVERT(DATETIME, '01/11/2007' ,3) AND
CONVERT(DATETIME, '30/11/2007' ,3)
David Portas wrote:
<sh***********@hotmail.comwrote in message
news:ac**********************************@r9g2000p rd.googlegroups.com...
I am able to extract dates in the correct format i.e.

SELECT CONVERT(VARCHAR(8), GETDATE(), 3)
=dd/mm/yy

My issue is that my users are selecting a date in this format and I
need to select data based on this range.

i.e.

SELECT * FROM TABLE
WHERE date BETWEEN '01/11/2007' AND '30/11/2007'
=The conversion of a char data type to a datetime data type resulted
in an out-of-range datetime value.
(Obviously expecting to see mm/dd/yyyy)

Next Try:
SELECT * FROM TABLE
WHERE CONVERT(VARCHAR(8), date, 3) BETWEEN '01/11/07' AND '30/11/07'
=Returns rows outside of required range

What do I need to do to select all data in my table where the data
range is between 01/11/07 AND 30/11/07 in this format dd/mm/yy ???


I assume these are DATETIMEs? DATETIMEs don't have any format in SQL Server.

After validating the users input, your client application should query the
database using DATETIME or SMALLDATETIME types (which don't have any
format).

Your queries therefore ought to look something like:

BETWEEN @dt1 AND @dt2

where @dt1 and @dt2 are DATETIME or SMALLDATETIME types.

In fact it is better to use >= and < rather than BETWEEN. DATETIME values
always contain both date and time elements. If you use BETWEEN then any
times after midnight on the last day of the period will be excluded.

--
David Portas
Jun 27 '08 #3

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

Similar topics

10
by: Fawke101 | last post by:
Hi there, I have a date field in SQL server - that holds dates as DD/MM/YYYY format (GB). Now, i have an ASP application that Adds/Edits records in this table; and i am having real problems...
9
by: Ed Crowley | last post by:
I have a DateTimePicker control on my form that is displaying the date format in UK format (dd/mm/yy). However, in my code dtpStartDate.Value gives a date in US format, but...
1
by: Tan | last post by:
Could anyone tell me how I can not use british date format using <globalization culture="en-GB" uiCulture="en-GB"/> in the webconfig with the line of code above i can not get the format is...
2
by: Rahul | last post by:
Hey Guys I have a development environment, in which the whole SQL syntax is stored in the Database. So the syntax in the databse column could be "where BirthDate = '12/31/2005' and ID =...
2
by: amatuer | last post by:
In Sa the date format is dd/mm/yy. in sql server the format the format is mm/dd/yy. What code can be used to chnge the format to the SA date format eithout chnging sql servers regional settings?
7
by: Richiep | last post by:
I am trying to get a UK format date of dd/mm/yyyy. Why does the following subroutine not return a valid date in a web form? The date returned is #12:00:00 AM# but the date I entered into the...
5
by: Saitir | last post by:
Example: On a web page the user enters for a date: 12/05/2006 They're in the UK, so this is 12th May 2006 Once this value arrives in a datetime variable in VB, date.month = 12 and not 5 as...
1
by: santiago | last post by:
Hello. I'm having troubles with a query that (should) return all the records between two dates. The date field is a datetime type. The db is SQL Server 2000. When I try this SELECT ...
10
by: ARC | last post by:
Hello all, General question for back-end database that has numerous date fields where the database will be used in regions that put the month first, and regions that do not. Should I save a...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.