Time Difference

  • Hello to all.

    I want to create a script to find all PurchaseOrders (from a PO Table) between @yesterday at 15:00 and @today at 08:00.

    How can I create this?

    SELECT PONum

    FROM PO

    WHERE

    (POStatusDate > CONVERT(DATETIME, '@yestrday 15:00:00', 102)) AND (POStatusDate < CONVERT(DATETIME, '@today 08:00:00', 102))
    BR,
    Konstantinos

  • Hi,

    Try this:

    declare @yesterday datetime

    declare @today datetime

    set @yesterday = convert(datetime,convert(varchar(11),dateadd(dd,-1,getdate()),106) + ' 15:00:00.000')

    set @today = convert(datetime,convert(varchar(11),getdate(),106) + ' 08:00:00.000')

    SELECT PONum

    FROM PO

    WHERE

    POStatusDate > @yesterday AND POStatusDate < @today

    Hope that helps,

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

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