none
i want a query - Which is larger than a date and a time, but time only on the first query is. (where date > '1391/11/02' and time > '10:21' )

    Question

  • hi

    i want a query - Which is larger than a date and a time, but time only on the first query is. (where date > '1391/11/02' and time > '10:21' )

    please see picture

    Saturday, July 06, 2013 10:20 PM

Answers

All replies

  • You cant do this using the sql server date data type.

    The lowest date value in sql server is 1753-01-01....

    The only way you can achieve this is by coding some fancy method of representing these dates.

    BTW, what data will you actually have dating back to 1391? - who would have actually recorded data from back then?

    Sunday, July 07, 2013 6:31 PM
  • hi

    <You cant do this using the sql server date data type.>

    <The lowest date value in sql server is 1753-01-01....>

    no date - this fields is Nvarchar(10)

    <BTW, what data will you actually have dating back to 1391? - who would have actually recorded data from back then?>

    2013/07/07 = 1392/04/16 Shamsi (Persian) Date

    Sunday, July 07, 2013 7:00 PM
  • I'm assuming that you have a separate date and time field.

    It should work something like this:

    create table #Mytest
    (
    	thedate nvarchar(10),
    	theTime nvarchar(10)
    )
    INSERT INTO #Mytest 
    SELECT '1391\11\02', '08:59' UNION ALL
    SELECT '1391\11\02', '10:23' UNION ALL
    SELECT '1391\11\03', '08:00' UNION ALL
    SELECT '1391\11\03', '23:50' UNION ALL
    SELECT '1391\11\04', '07:59' UNION ALL
    SELECT '1391\11\04', '10:24'
     
    SELECT
    	*
    FROM
    	#Mytest 
    WHERE
    	theDate >= '1391/11/02' AND theTime > '10:21'
    

    Sunday, July 07, 2013 7:09 PM
  • Sorry - you probably want this:

    SELECT
    	*
    FROM
    	#Mytest 
    WHERE
    	(theDate = '1391\11\02' AND theTime > '10:21') OR
    	thedate > '1391\11\02'
    	
    

    Sunday, July 07, 2013 8:11 PM