"select results that are only between today and 2 days in the future" Code Answer

5

if estimatedtime column is declared as datatype datetime or date, then it's straightforward:

where t.estimatedtime >= date(now())
  and t.estimatedtime  < date(now()) + interval 2 day

now() returns the current date and time, the date() function trims off the time portion, making it equivalent to midnight.


if the column is declared as character type, rather than datetime (but why in god's green earth would you do that?), convert the datetime expression to character in an appropriate canonical format, so that string comparisons will work appropriately:

where t.estimatedtime >= date_format(date(now())                 ,'%y%m%d%h%i%s')
  and t.estimatedtime  < date_format(date(now()) + interval 2 day,'%y%m%d%h%i%s')

if estimatedtime is stored as a numeric (integer) datatype, then convert the string to numeric by adding a zero...

where t.estimatedtime >= date_format(date(now())                 ,'%y%m%d%h%i%s')+0
  and t.estimatedtime  < date_format(date(now()) + interval 2 day,'%y%m%d%h%i%s')+0
By Durim on September 15 2022

Answers related to “select results that are only between today and 2 days in the future”

Only authorized users can answer the Search term. Please sign in first, or register a free account.