Ask a Question related to Microsoft SQL / MS SQL Server, Design and Development.
-
Ian Piper #1
Help with Dates please
Hi,
In a SQL table I have a field named departure and a date in inserted in it.
What is the exact syntax to get only records with a future date (in
departure field) please.
The SQL data type for departure is 'datetime'
I have tried SELECT *
FROM dbo.table
WHERE Departure_date> ' & date() & '
and I get the error 'syntax error converting datetime from character string'
Many thanks in advance
Ian
Ian Piper Guest
-
Between Dates
I am trying to query an online access database and return records that have occurred between dates. I am using another query which does work to... -
Dates & SQL
In my CF form I have created a date object using #DateFormat(Now(),"MM/DD/YY")# which displays the date as: 07/29/05. When the date is inserted... -
ASP/VBS Dates Between Dates
I'm trying to filter records depending on 2 dates requested from the querystring MMColParam1 (startdate) and MMColParam2 (enddate), i.e. a list... -
Dates again
Hello all I'm having trouble getting iis to understand the UK format of dates ASP off a MS Access database I have the following query:... -
Dates
Thanks to all those who replied. I ended up doing some research myself and found a good date module at... -
Bob Barrows #2
Re: Help with Dates please
You will need to convert date() into a date format that the SQL Server can
recognize. The safest format is YYYYMMDD. I would create a function that
returns a string containing the properly formatted date.
Without more details as to what you are writing this in (VB? vbscript?) I
can't provide more details. If it's VB, you don't even need a function: you
can use the builtin Format function.
HTH,
Bob Barrows
Ian Piper wrote:> Hi,
>
> In a SQL table I have a field named departure and a date in inserted
> in it.
>
> What is the exact syntax to get only records with a future date (in
> departure field) please.
>
> The SQL data type for departure is 'datetime'
>
> I have tried SELECT *
> FROM dbo.table
> WHERE Departure_date> ' & date() & '
> and I get the error 'syntax error converting datetime from character
> string'
>
> Many thanks in advance
>
> Ian
Bob Barrows Guest
-
Aaron Bertrand - MVP #3
Re: Help with Dates please
> You will need to convert date() into a date format that the SQL Server can
Well, you don't really need to do this... the date doesn't need to come from> recognize. The safest format is YYYYMMDD. I would create a function that
> returns a string containing the properly formatted date.
the application; SQL Server knows what the current date is, so you can avoid
these formatting issues altogether...
Aaron Bertrand - MVP Guest
-
Ian Piper #4
Re: Help with Dates please
Thanks Aaron, that works great.
Regards
Ian
"Aaron Bertrand - MVP" <aaron@TRASHaspfaq.com> wrote in message
news:OpZWIBMRDHA.2096@TK2MSFTNGP12.phx.gbl...> If by "future date" you mean any date/time with a date greater than today,
> then
>
>
> SELECT * FROM dbo.table WHERE
> Departure_date >= DATEADD(DAY, 1, {fn CURDATE()})
>
>
> "Ian Piper" <ipiper001@NOSPAM.btinternet.com> wrote in message
> news:beci9l$4go$1@hercules.btinternet.com...> it.> > Hi,
> >
> > In a SQL table I have a field named departure and a date in inserted in> string'> >
> > What is the exact syntax to get only records with a future date (in
> > departure field) please.
> >
> > The SQL data type for departure is 'datetime'
> >
> > I have tried SELECT *
> > FROM dbo.table
> > WHERE Departure_date> ' & date() & '
> > and I get the error 'syntax error converting datetime from character>> >
> > Many thanks in advance
> >
> > Ian
> >
> >
>
Ian Piper Guest
-
Bob Barrows #5
Re: Help with Dates please
Aaron Bertrand - MVP wrote:
Future reference, in case the date to be passed isn't today's date :-)>>> You will need to convert date() into a date format that the SQL
>> Server can recognize. The safest format is YYYYMMDD. I would create
>> a function that returns a string containing the properly formatted
>> date.
> Well, you don't really need to do this... the date doesn't need to
> come from the application; SQL Server knows what the current date is,
> so you can avoid these formatting issues altogether...
Again overlooking the obvious,
Bob
Bob Barrows Guest



Reply With Quote

