I want to export some data from test_records
table depend upon supplied from date and to date
. I from and to date not supplied I want to export whole data. So how I can achieve that. Below is my code.
$from_date = strtotime($form_state['values']['fromdate']." 00:00:00");
$to_date = strtotime($form_state['values']['todate']." 23:59:59");
$result = db_select('test_records', 'n')
->fields('n')
->condition('submitted_time', array($from_date, $to_date), 'BETWEEN')
->execute()
->fetchAll();
I am using one condition that will compare submitted_time
in database with supplied from
and to
dates. But When I pass nothing, it should get all the data from that table. Any suggestion will be appreciated.