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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:34:26+00:00 2026-05-16T23:34:26+00:00

I have a date that comes from a MySQL database in the datetime format,

  • 0

I have a date that comes from a MySQL database in the datetime format, something like 2010-09-24 11:30:12. And I need a way to show a countdown of hours:mins to that date.

I’m not very familiar with dates in JavaScript so any help would be apreciated. Thanks.

  • 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-16T23:34:27+00:00Added an answer on May 16, 2026 at 11:34 pm

    You may want to use the UNIX_TIMESTAMP() function in MySQL to return your date in Unix Time Format (the number of seconds since January 1, 1970). Let’s say our target date is '2011-01-01 00:00:00' (in reality you would probably have a field from your table, instead of a constant):

    SELECT UNIX_TIMESTAMP('2011-01-01 00:00:00') AS timestamp;
    +---------------+
    | timestamp     |
    +---------------+
    | 1293836400    |
    +---------------+
    1 row in set (0.00 sec)
    

    Then we can use the getTime() method of the Date object in JavaScript to calculate the number of seconds between the current time and the target time. Once we have the number of seconds, we can easily calculate the hours, minutes and days:

    var target = 1293836400;    // We got this from MySQL
    var now = new Date();       // The current tume
    
    var seconds_remaining = target - (now.getTime() / 1000).toFixed(0);
    var minutes_remaining = seconds_remaining / 60;
    var hours_remaining = minutes_remaining / 60;
    var days_remaining = hours_remaining / 24;
    
    alert(seconds_remaining + ' seconds');     // 8422281 seconds
    alert(minutes_remaining + ' minutes');     // 140371.35 minutes
    alert(hours_remaining + ' hours');         // 2339.5225 hours
    alert(days_remaining + ' days');           // 97.48010416666666 days
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a date and I would like to format the date like that:
I have a folder with backups from a MySQL database that are created automatically.
I have a script that grabs data from a MySQL database table and creates
I have a MySQL Database That Looks like This: Name: Joe Items: 25 CreationDate:
I'm using .NET 3.5 and I have a date that comes in as string
Let's say I have a date that I can represent in a culture-invariant format
I have been passed a date string that looks like this: Thu%20Mar%2011%202010%2015%3A09%3A11%20GMT%2B0000%20(BST) I want
I have a Date format: 2009-08-10T16:03:03Z that I want to convert to: @MMM dd,
I have a video gallery where the data is coming from a mysql database.
I have a query reading a date from a parent/child relationship and i need

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.