-1

I need to subtract 5 hours if the datetime falls before 03/09/2014 saving and 4 hours if it's after 03/09/2014. It's in a case statement this is what I have so far but it's only hitting the first when and not working with the second when.

max(
  Case 
       when aa.status_id=10 and aa.created_at <'3/09/2014'
            then DATE_SUB(aa.created_at,  interval 4 HOUR) 
       when aa.status_id=10 and aa.created_at >'3/09/2014'
            then DATE_SUB(aa.created_at,  interval 4 HOUR)
       else null
  end )as  form_Receieved
Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82

1 Answers1

0

first you are substracting 4 hours from date ! which will not work , it must be datetime.

second you comparing between datetime column and date . you have to convert it to datetime. or make it same as your column format.

      when aa.status_id=10 and aa.created_at <'2014-03-09 00:00:00' 

assuming that created_at is datetime column because you didnt show your table and columns structure.

echo_Me
  • 37,078
  • 5
  • 58
  • 78