Hour not showing correctly

  • --Question 4b

    select

    History_Type_,

    TimeClicked,

    left(right(TimeClicked,11),2) as HourTimeClicked,

    count(left(right(TimeClicked,11),2)) as CountOfHourTimeClicked

    from clicktracking_ --with (nolock)

    inner join members_ on clicktracking_.MemberID_ = Members_.MemberID_

    group by

    History_Type_,

    timeClicked,

    left(right(TimeClicked,11),2)

    OPN2011-09-24 18:38:000169

    OPN1802013-04-02 12:41:00011

    OPN902013-04-11 18:18:00011

    OPN1802011-09-26 13:08:000113

    OPN902011-07-05 11:01:000117

    the hour is always incorrectly 01 which is wrong

    please can someone help?

  • philip.davy (5/17/2013)


    --Question 4b

    select

    History_Type_,

    TimeClicked,

    left(right(TimeClicked,11),2) as HourTimeClicked,

    count(left(right(TimeClicked,11),2)) as CountOfHourTimeClicked

    from clicktracking_ --with (nolock)

    inner join members_ on clicktracking_.MemberID_ = Members_.MemberID_

    group by

    History_Type_,

    timeClicked,

    left(right(TimeClicked,11),2)

    OPN2011-09-24 18:38:000169

    OPN1802013-04-02 12:41:00011

    OPN902013-04-11 18:18:00011

    OPN1802011-09-26 13:08:000113

    OPN902011-07-05 11:01:000117

    the hour is always incorrectly 01 which is wrong

    please can someone help?

    Don't try to parse datetime as string. Use relevant datetime functions instead:

    SELECT ...

    DATEPART(HOUR,TimeClicked) AS HourTimeClicked

    ....

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Many thanks - this works perfectly

Viewing 3 posts - 1 through 2 (of 2 total)

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