Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string to type timestamp in rails

I have the following string 2012-7-31 09:38:00.000000 which I want to convert to type timestamp (without time zone) in PGadmin. Which methods in ruby can get the job done?

Thanks

like image 537
Vigrant Avatar asked Dec 21 '22 18:12

Vigrant


1 Answers

Try

DateTime.parse("2012-7-31 09:38:00.000000")

#output
Tue, 31 Jul 2012 09:38:00 +0000

DateTime.parse("2012-7-31 09:38:00.000000").to_i
#output is timestamp
1343727480 
like image 123
Kulbir Saini Avatar answered Jan 04 '23 07:01

Kulbir Saini