ROR + Ruby Date Decrease by 15 minutes

If I have @time = Time.now.strftime("%Y-%m-%d %H:%M:%S"),

How can I reduce this time by 15 minutes ?

I already tried this one :: @reducetime = @time-15.minutes, works fine at console but give errors while execution. Other than this Is there any way to resolve this issue.

Thanks

Answers


Your problem is that you're formatting your time into a string before you're done treating it as a time. This would make more sense:

@time       = Time.now
@reducetime = @time - 15.minutes

# And then later when you're reading to display @time...
formatted_time = @time.strftime("%Y-%m-%d %H:%M:%S")

You shouldn't format your data until right before you're ready to display it.

If you must have @time as the formatted time then you're going to have to parse it before computing @reducetime:

@reducetime = (DateTime.strptime(@time, "%Y-%m-%d %H:%M:%S") - 15.minutes).to_time

Need Your Help

Scale Entire Site

html css html5 css3

I essentially want to be able to scale the entire site (images, elements, the whole sha-bang) to what ever browser size window the user is using. Anyone have success doing this and would be willing...

Two way communcating server/client architecture?

c# wcf sockets architecture client-server

I'm trying to figure out which client/server technology (i.e. which part of the .NET Framework) to use for our new application. We will be writing the app in C# using .NET 3.5 SP1.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.