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

  • Home
  • SEARCH
  • 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 6689423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:31:03+00:00 2026-05-26T05:31:03+00:00

I am taking a javascript new Date() and trying to format it as a

  • 0

I am taking a javascript new Date() and trying to format it as a string like so:

yyyy-MM-dd hh:mm:ss

and then insert it into a SQLite database. I am using Appcelerator (1.7.2) which uses the Mozilla Rhino engine for JS.

Here is the function:

date.DateToSQLite = function(date){
if (date == null){
    return null;
}  else if (date instanceof Date == false){
    throw "not a date Object value:" + date;
};
var result  = date.getUTCFullYear();
result += '-';
if (date.getUTCMonth() < 9){
    result += '0';
}
result += date.getUTCMonth() +1;
result += '-';
if (date.getUTCDate() < 10){
    result += '0';
}
result += date.getUTCDate();
result += ' ';
if (date.getUTCHours() < 10){
    result += '0';
}
result += date.getUTCHours();
result += ':';
if (date.getUTCMinutes() < 10){
    result += '0';
}
result += date.getUTCMinutes();
result += ':';
if (date.getUTCSeconds() < 10){
    result += '0';
}
result += date.getUTCSeconds();
result += '.';
if (date.getUTCMilliseconds() < 100){
    result += '0';
}
if (date.getUTCMilliseconds() < 10){
    result += '0';
}
result += date.getUTCMilliseconds();

//Ti.API.info('date.DateToSQLite result:' + result + ' date:' + date);

return result;

};

I can’t recreate this myself, the function appears to always work for me, but some client’s databases show NAN-NAN-NAN NAN:NAN:NAN.NAN and this can go on for up to 40 minutes and then it starts working again.

Here is a screenshot of the field from a SQLite database as viewed in Navicat:

Showing errors in Database

Showing design view of database

Can date.getUTCHours() or date.getUTCMinutes() return NAN:NAN?

Do I have to use UTC? My clients are in the Middle East.

This is an Titanium Appcelerator application running on iOS / iPad2 devices.

  • 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-26T05:31:03+00:00Added an answer on May 26, 2026 at 5:31 am

    While the code is sort of … icky … it is not possible for any working JavaScript’s Date object to return NaN from the “getTimePart” methods:

    1. Ensure the client(s) are using the expected code (not an old version), and;
    2. Ensure the client(s) don’t have an absolutely broken JavaScript implementation, and;
    3. There is no obscure — e.g. custom — “Date” object be used on said funky client(s)

    It may also be possible that said environment(s) just have broken “getUTCTimePart” methods; can the symptoms be repeated with the non-UTC components?

    Happy coding.

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

Sidebar

Related Questions

this is my code for taking external page into div using ajax what i
I am writing the replace function in javascript taking account into word boundary blog
I have a new-ish rails 3.1.1 app using sass/compass with compass taking care of
I'm taking an adventure into the depths of JavaScript and have come across a
Taking CPU affinity into account, will such an environment be useful with threading? Or
Taking the jQuery framework for example, if you run code like this: $(document).ready(function init()
When taking a database from a relatively un-normalized form and normalizing it, what, if
I am trying to work out some performance problems with some JavaScript I've been
thanks for taking the time to read this. I have a JavaScript (jQuery) navigation
ok, I'm writing a little code snippet to get the ISO date-format value for

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.