date convert function - error

  • the syntax working with fixed date and time


    SELECT LAST_UPDATED_TIMESTAMP  FROM WORKING_HRS WHERE LAST_UPDATED_TIMESTAMP  between '2018-10-02 06:00:00' and '2018-10-03 06:00:00'

    Dynamic date range after convert datetime function not fetching


    SELECT LAST_UPDATED_TIMESTAMP  FROM WORKING_HRS WHERE LAST_UPDATED_TIMESTAMP  convert(datetime,GETDATE()-2,'06:00:00') and convert(datetime,GETDATE()-1,'06:00:00')

    Error - Argument data type varchar is invalid for argument 3 of convert function.

  • What is your question?

    '06:00:00' is not a valid argument 3 for CONVERT, the error message is clear.

    The absence of evidence is not evidence of absence.
    Martin Rees

    You can lead a horse to water, but a pencil must be lead.
    Stan Laurel

  • SQL Galaxy - Thursday, October 4, 2018 7:24 AM

    the syntax working with fixed date and time


    SELECT LAST_UPDATED_TIMESTAMP  FROM WORKING_HRS WHERE LAST_UPDATED_TIMESTAMP  between '2018-10-02 06:00:00' and '2018-10-03 06:00:00'

    Dynamic date range after convert datetime function not fetching


    SELECT LAST_UPDATED_TIMESTAMP  FROM WORKING_HRS WHERE LAST_UPDATED_TIMESTAMP  convert(datetime,GETDATE()-2,'06:00:00') and convert(datetime,GETDATE()-1,'06:00:00')

    Error - Argument data type varchar is invalid for argument 3 of convert function.

    The third argument in the convert should be the Date and time style - it has no idea what you mean by '06:00:00'. You can find the list of integers used for the styles in the documentation for Cast and Convert:
    CAST and CONVERT (Transact-SQL)

    Sue

  • Furthermore, GETDATE() returns DATETIME, so converting from DATETIME to DATETIME is an identity operation.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

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

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