jeudi 23 février 2017

undefined method `to_date' for nil:NilClass with random date

I use this code to generate date:

DateTime.strptime("10/26/2015 07:09:52 AM", '%m/%d/%Y %I:%M:%S %p')

But when I use this code to generate random date:

(Time.now - rand(15552000)).strftime('%m/%d/%Y %I:%M:%S %p')

I get error:

undefined method `to_date' for nil:NilClass

Can you give some solution how I can fix this?




Aucun commentaire:

Enregistrer un commentaire