0

Okay kindly refer the below code then I'll put my question.

#!/usr/bin/bash

#scirpt to connect with db

master_db_user='root'
master_db_passwd='123'
master_db_port='3306'
master_db_host='localhost'
master_db_name='uppcldashboard'

Now=$(date +"%d-%m-%Y")
date=$(date +"%F")


#Preparing script

#SQL_Query='select * from test_table;'

#MySql Command to connect to a database

#mysql -u$master_db_user -p$master_db_passwd -D$master_db_name -e "select * from uppcl_amount_details into outfile '/created_files/uppcl.csv' fields terminated by ',' lines terminated by '\n';"

mysql -u$master_db_user -p$master_db_passwd -D$master_db_name -e "select * from uppcl_amount_details where posting_date='$date' into  outfile '/created_files/uppcl.csv' fields terminated by ',' lines terminated by '\n';"

mv /created_files/uppcl.csv /created_files/offline_collection$Now.csv

sed -i "1i id","Cashier_id","Cheque_no","collection_amount","collection_type","Posting_date","Discom","Division_Code","Division_Name","Head_cashier_id","ref_3","ref_4","ref_5","ref_6","ref_7","ref_8","Tran_Date","Status","Posting_Updated_Date" /created_files/offline_collection$Now.csv
echo "End of the Script"

okay so the things I'm able to fetch date which have date like this 2020-04-15 00:00:00 but I'm not able to fetch data which have date 2020-04-15 12:12:10.

so I was thinking if there is a way by which I fetch data from the db in this format %Y-%m-%d and then use my date variable ($Now) to extract all data.

Is there any way

Neep Help On this Asap.

Thanks and Regards, Sagar Mandal

1 Answer 1

0

By default sql will take 2020-04-15 00:00:00 if we give only date value for datetime parameter. Use wildcard to list all logs from the date.

Try as

posting_date LIKE '$date%'

You must log in to answer this question.