1

I have 2 columns to ORDER BY -- date, day ..

+------------------+---------------------+
| day_to_send      | date_to_send        |
+------------------+---------------------+
|     25           | 0000:00:00 00:00:00 |
|     18           | 0000:00:00 00:00:00 | 
|     11           | 0000:00:00 00:00:00 | 
|     NULL         | 2018-11-20 04:41:12 |
|     NULL         | 2019-04-11 10:50:12 |
|     NULL         | 2018-11-19 11:30:12 |
+------------------+---------------------+

Output should be

 1. 2018-11-19 11:30:12
 2. 2018-11-20 04:41:12
 3. 2019-04-11 10:50:12
 4. 11
 5. 18
 6. 25

I have tried so far, date ASC/DESC, and day ASC/DESC but i couldn't achieve this somehow.. any help would be highly appreciated.

->orderBy('date_to_send', 'ASC')
->orderBy('day_to_send', 'ASC')

I am using Laravel 4

MY OUTPUT, What I am getting

enter image description here

Syed Saqlain
  • 544
  • 4
  • 21

1 Answers1

0

ok, I have found a solution to do this.. just pasting my answer if someone needed in future.. The sorting was not working properly due to datatype of my day_to_send column.

I have changed the datatype of this column from varchar to int and applied the below query and it worked..!

->orderBy('date_to_send', 'ASC')    
->orderBy('day_to_send', 'ASC')

Thanks to all those who contributed.. Cheers

Syed Saqlain
  • 544
  • 4
  • 21