Re: Date conversion

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Steve Kass (skass_at_drew.edu)
Date: 08/21/04


Date: Sat, 21 Aug 2004 11:05:43 -0500

Maziar,

  One solution is

select dateadd(day, datediff(day, 0, StartDate),0)

If you need the result to be of type smalldatetime, use

select cast(dateadd(day, datediff(day, 0, StartDate),0) as smalldatetime)

Steve Kass
Drew University

"Maziar Aflatoun" <maz00@rogers.com> wrote in message
news:c5KVc.8897$UYx.1082@twister01.bloor.is.net.cable.rogers.com...
> Hi everyone,
>
> I have a database with a date field 'StartDate' as smalldatetime. I need
to
> grab the date part and not the time part.
>
> Ex. 2004-08-01 00:00:00 all I need is the 2004-08-01
>
> How do I do that using SQL (Convert or Cast?? )?
>
> Also, is there another datatype I can define it as in the the database so
> that it's only date not time and date like date in MySQL.
>
> Thank you
> Maz
>
>
>
>
>



Relevant Pages

  • Debugging Scalar database functions in vS .NET (Parameter issue)
    ... I am trying to debug a function that I wrote on the SQL ... function has three parameters including two smalldatetime ... this input parameter ... The database output is the following: ...
    (microsoft.public.vsnet.general)
  • Re: Database Tripled In Size!!
    ... Check Database Properties> Files Page. ... Thursday night backup. ... from smalldatetime to datetime. ... have been related to the new data type. ...
    (comp.databases.ms-sqlserver)
  • DateTime problem: how to create datetime format hh:mm:ss AM/PM without the date
    ... my database has separate field for date and time so we can capture ... In Sql, date can be present in smalldatetime ... format, which contains only time hh:mm:ss AM/PM. ...
    (microsoft.public.dotnet.languages.csharp)
  • smalldatetime overflow error
    ... database and am having trouble with datetime fields into ... smalldatetime fields - I get "smalldatetime overflow error" I ...
    (borland.public.delphi.database.ado)
  • RE: CONVERT statements containing variables
    ... > I'm trying to convert this value to one of type SMALLDATETIME. ... > I created another variable using the DECLARE statement of type SMALLDATETIME: ... I tried a simple SQL statement in query anylyzer: ...
    (microsoft.public.sqlserver.programming)