Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:25:44+00:00 2026-06-14T21:25:44+00:00

I have a column called test_date , type datetime in General Exam table. I

  • 0

I have a column called test_date, type datetime in General Exam table. I built a form to create and update GeneralExam, on form, I allow User choose a date and time throught jQuery UI Datepicker.

After user choose date and time, it will displayed in textfield, like:

25-11-2012 16:30

It is my current time. When I run in console, I see the test_date was saved in database is:

2012-11-25 09:30:00

And when I get object GeneralExam, and get test_date value, it is:

g = GeneralExam.last
g.test_date
=> Sun, 25 Nov 2012 16:30:00 ICT +07:00

I think test_date is converted, because I set up in application.rb is:

config.time_zone = 'Hanoi'

But when I update a General Exam on form, it still display the time was saved in database, not my local timezone, it means it display:

2012-11-25 09:30:00

But I want it is like what I chose on form:

25-11-2012 16:30:00

How can I set up for display datetime column in local time?

And I think the order of date was reversed, when I choose date, it is 25-11-2012, but when it displayed it was 2012-11-25, Why it reversed the order?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:25:46+00:00Added an answer on June 14, 2026 at 9:25 pm

    After few hours I search on google and stackoverflow, I think I found what I want. I have looked at this question and find some information about strftime method. This is what information I need to solve my problem.

    First, How to display datetime was saved in UTC as local time when display it:

    Value was saved:                             2012-11-25 09:30:00
    
    Value I want display on form (ICT +7:00):    25-11-2012 16:30:00
    

    To display value I want, I used this on form (I used simple_form):

    <%= f.input :test_date, as: :string, label: false, input_html: { id: "datetime_picker", value: f.object.test_date.strftime("%d-%m-%Y, %H:%M") } %> 
    

    I have got value in database and format it by:

    value: f.object.test_date.strftime("%d-%m-%Y, %H:%M") } %> 
    

    And when I want display test_date in table data, I also used strftime("%d-%m-%Y, %H:%M") to display datetime format as I want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In database table I have column called options . It has type of integer
In mysql database i have this column called: Name: Date Type: datetime I have
I have the column DateTimeExpired, and I would like to create another column called
I have a postgres table with a column (called id) which contains strings. In
I have a table called test, which only has 1 column, NullableInt (nullable int
I have a table setup with a UNIQUE column called, for example, test .
I have a table that I added a column called phone - the table
I have a table called audits which has a column 'changes' storing data in
I have a mysql table in which there is a column e.g. called name.
I have a table called Test and I have a column called Date which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.