I have the following scenario where I have a datetime that I would like to reparse. I can get the following to work in irb, but I seem to be having an issue with nil values when working with post parameters. for ex.
This works in irb:
DateTime.strptime("10/25/2012 04:27 pm", "%m/%d/%Y %I:%M %P").strftime("%Y-%m-%d %H:%M:00")
=> "2012-10-25 16:27:00"
However when I try to access a params value I can’t seem to access the value itself. for ex.
def create
@shipment = params[:shipment]
@shipment.ship_date = format_date(@shipment.ship_date)
.
.
.
end
def format_date(date)
DateTime.strptime(date, "%m/%d/%Y %I:%M %P").strftime("%Y-%m-%d %H:%M:00")
end
When I set a variable manually with a string it works. When I try to work off the parameter it seems to be nil. even when I do @shipment.ship_date.to_s it converts it to “” I know that parameter is not empty as it shows in the web inspector of my browser. I must not know how to work with parameter values.
should work