How to insert only only time in a datetime field

  • How to insert only only time in a datetime field.

    Allway insert in long format 01/01/1900 01:30:00 a.m.

    I want to store only time!!!

     

    How?

     

     

  • No chance! A DATETIME always contains a DATE *and* a TIME part. See, if this helps:

    http://www.karaszi.com/sqlserver/info_datetime.asp

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Ok.

    Thank you.

  • Obviously you could convert the time to a char based format and store in a SQL char or varchar field. I don't think this strategy this would be useful except for presentation unless the client tool would find this easier to work with.

  • Hey, no need to worry! SQL Server 2005 will adress this, I think.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Hi,

     

    How i doing to retrieve a set of records a range of time in a week.

    I want to get a perfil of my users on a range of time, but of a week, in a only step.

    Not SUM(Day1,Day2,etc ), i do not want this.

     

  • I think this helps to find the right time:

     

    select DATEPART(hh,getdate())as stunde,DATEPART(mi,getdate()) as minute

     

    or do it so...

     

    declare @hour CHAR(2)

    declare @minute char(2)

    set @hour = DATEPART(hh,getdate())

    set @minute =DATEPART(mi,getdate())

    print @hour+@minute

  • It would be a little easier if you could explain what you are trying to do - how the desired result should look and your intentions with it. A few rows of example data showing what it looks like in the table would also help.

    /Kenneth

  • hi,

    Try doing this

    select

    substring(cast(getdate() as varchar(30)),13,Len(cast(getdate() as varchar(30))))

  • Unfortunately, that's not going to work so well - it doesn't provide the output you may expect. It's often not a good idea to rely on supposed defaults, it will bite you sooner rather than later. (you must control the displayed format when doing string operations on a 'date')

    In any case, if you just want to find the timeportion of a datetime, select convert(char(8), getdate(), 108) is probably the best way.

    What I'm still curious about, is what the original poster really wants..? I don't quite grasp the meaning of 'a range of time within a week'. A week has no concept of 'time' as in hours and minutes, weeks are measured in days. So, I assume there is more to the question than just how to find the 'time'...

    /Kenneth

     

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply