Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting a string and assigning to different variables

I have got the date range from the ui as - approved_between"=>"2013-03-17 - 2013-03-18"

I need to split this approved_start_date="2013-03-17" and approved_end_date="2013-03-18"....I am hoping to use this to query in mysql as the date format in mysql is created_at: 2012-07-28 10:35:01.

What I'm doing is-:

approved = approved_between.split(" ")
approved_start_date = approved[0]
approved_end_date = approved[2]

Pretty sure this isn't the most optimum way to process it, any better suggestions out there like split string in a single line, and assign them directly to variable?

like image 891
Pratik Bothra Avatar asked Mar 18 '13 09:03

Pratik Bothra


1 Answers

that should be

approved_start_date, approved_end_date = approved_between.split(" - ")

UPDATE: using the dates in mysql

MyModel.where('DATE(created_at) = ?', approved_start_date)
like image 134
jvnill Avatar answered Sep 27 '22 23:09

jvnill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!