Pavel
Pavel

Reputation: 4420

how to store current date+ current time in database

I have a problem. I want to store current date+ time in my database. I was trying to make a migration like

current_time:date

and

current_time=DateTime.now 

but it stores current date only, also i was trying to do

current_time:time

in migration. and then

current_time=Time.now 

or

current_time=DateTime.now

But it stores only current time, another parametres are 2000-01-01. What I am doing wrong?

Thanks in advance.

Upvotes: 3

Views: 1011

Answers (1)

davidb
davidb

Reputation: 8954

Use timestampin your migration. Of cause dateonly stores dates and timeonly stores time but timestampstores the secounds since the 01.01.1970 00:00 and that an absolute time definition.

current_time:timestamp

To add some days you can do

instance.current_time+=3.days

Upvotes: 3

Related Questions