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 7404203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:13:21+00:00 2026-05-29T05:13:21+00:00

I store dates in the DATETIME format in a MySQL database. When a model

  • 0

I store dates in the DATETIME format in a MySQL database. When a model is fetched from the database, dates (in the DATETIME format) are converted to date objects in the model’s initialize method. So far so good.

When the model is saved to the server, the date objects need to be converted back to the DATETIME format in order for the server side code to interpret the dates correctly. I have used all sorts of hackery to do this, but I wonder at what stage can of the model’s save method can I safely convert the dates to the DATETIME format?

One approach is to do the following:

this.model.save({
    date : date.toDateTime()
}, options);

However, this causes a change event to be fired since the attributes hash before the save method is not the same as the hash after the save event (and this triggers Backbone’s set method).

  • 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-05-29T05:13:22+00:00Added an answer on May 29, 2026 at 5:13 am

    I would advice using UNIX time (number of seconds/milliseconds from 1970) both in model and in the interface and converting to readable date only in View.

    So the server both sends and receives dates as numbers like 1328281766454 and this is how you store them in Backbone.Model. When it has to be rendered in View you can simply call:

    new Date(this.model.get('someTime'));  //Fri Feb 03 2012 16:09:26 GMT+0100 (CET)
    

    The same can be done on the server side. Believe me, this is the simplest and most portable way of transfrering dates without all these time-zone issues.

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

Sidebar

Related Questions

In mysql database I store date column as unix-timestamp format (for example: 1264105904 ).
Can any body tell me how can I store Java Date to Mysql datetime...?
I have a DateTime which I want to store in a Date MySQL column.
I have date and time stored in my database as MySQL DATETIME datatype. While
Date and time in MySQL can be stored as DATETIME, TIMESTAMP, and INTEGER (number
I have legacy DB that store dates that means no-date as 9999-21-31, The column
I am working with an old mysql database in which a date is stored
I am storing all my dates in UTC format in my database. I ask
I have a SQLite database where I store the dates as ticks. I am
Duplicate Managing date formats differences between PHP and MySQL PHP/MySQL: Convert from YYYY-MM-DD to

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.