Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

SQL: comparing date with datetime field

LEGEND ,
Apr 10, 2008 Apr 10, 2008
I'm having a brain fart as I assume this is really simple.

Given that I have the date in the format of yyyy/mm/dd, how do I put that
into a sql query that compares that to the datetime field?

It appears the datetime field, by default, uses this format: m/d/yyyy
hh:mm:ss am

-Darrel


TOPICS
Server side applications
337
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 10, 2008 Apr 10, 2008
On 10 Apr 2008 in macromedia.dreamweaver.appdev, darrel wrote:

> I'm having a brain fart as I assume this is really simple.
>
> Given that I have the date in the format of yyyy/mm/dd, how do I put
> that into a sql query that compares that to the datetime field?
>
> It appears the datetime field, by default, uses this format:
> m/d/yyyy hh:mm:ss am

What dbms?

--
Joe Makowiec
http://makowiec.net/
Email: http://makowiec.net/contact.php
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 10, 2008 Apr 10, 2008

> What dbms?

t-sql (MSSQL)

For now, via string functions, I rearrange the date/time format manually,
and then use the CAST statement in the SQL query. Not pretty, but seems to
work.

-Darrel


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 11, 2008 Apr 11, 2008
LATEST
If your date formats are different you will have to use CAST or CONVERT
functions as you state you already have. If this works then stick with it.
You may also need to use a SET DATEFORMAT command. See below:

http://msdn2.microsoft.com/en-us/library/ms189491.aspx

Dates in SQL Server can be a bit of a pain to work with. It is usually best
practice to store your DateTime data in raw format and use CAST or CONVERT
functions in your Stored Procs to get the correct results.

Pat.

"darrel" <notreal@nowhere.com> wrote in message
news:ftloim$jv4$1@forums.macromedia.com...
>
>> What dbms?
>
> t-sql (MSSQL)
>
> For now, via string functions, I rearrange the date/time format manually,
> and then use the CAST statement in the SQL query. Not pretty, but seems to
> work.
>
> -Darrel
>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines