Need to convert Datetime field

  • I need to pass the number of seconds as an integer number from a datetime field to a RS report. i.e. value '2009-02-04 00:00:00.000' but I'm not sure what the sql syntax ix.

    Any clues?

    thx,

    John

  • Clarify please, number of secods from when?

  • Have you looked at the DatePart function? Won't that do what you need?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I apologize. Actually I need to pull the hh:mm:ss from the datetime field. The sample value is 2009-02-04 12:29:49.753

    Hope this helps,

  • [font="Verdana"]I'd suggest you start with the datepart function. Look it up in SQL Server Books Online (BOL).[/font]

  • latingntlman (2/4/2009)


    I apologize. Actually I need to pull the hh:mm:ss from the datetime field. The sample value is 2009-02-04 12:29:49.753

    Hope this helps,

    Little more clarification, you need to pass this for above: 12:29:49.753?

  • I need to display the time when the subscription ran. For example; a subscription ran at 20:59:58 on 02-03-2009, which would be the value in field RunDate '2009-02-03 20:59:58.687'.

    Also, please notice that the sample time above means the job ran at 8:59:58 PM. My preference is not to show it in military time. Right now I'm using syntax CONVERT(varchar(10),TimeStart,108) and it works but it gives me military time (20:59:58). I'm almost there.

  • Try this: select right(convert(varchar(40), getdate(), 109), 14)

  • [font="Verdana"]Are you displaying this in a reporting services report? Because if so, you can return the actual datetime value, and then change the field format on the report so that it only display the time portion.

    Otherwise, try something like this:

    select substring(convert(varchar, getdate(), 109), 13, 14)

    [/font]

  • Lynn and Bruce, unfortunately that doesn't give me the desired results. I'll just take the easy route and format it in RS.

    thx,

    John

  • Actually, that is the best idea yet.

  • Gotta agree with that one. If it's being formatted for human-readability, it's better to do that in the presentation layer, not in the database.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

Viewing 12 posts - 1 through 11 (of 11 total)

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