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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:11:36+00:00 2026-06-03T15:11:36+00:00

Okay I have the following problem. I want to get the current dateTime and

  • 0

Okay I have the following problem. I want to get the current dateTime and then want do check if a date that I enter is bigger than the current DateTime. The format of my dateTime should look like this.

03/11/2012 09:37 AM

Here is the function how I get the current DateTime.

function getCurrentDateTime()
{
    var currentTime = new Date()
    // Date
    var month = currentTime.getMonth() + 1;
    if (month < 10){
        month = "0" + month;
    }
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();

    // Time
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();
    if (minutes < 10){
        minutes = "0" + minutes;
    }

    if(hours > 11){
        var dateString = month + "/" + day + "/" + year + " " + hours + ":" + minutes + " " + "PM";
        test = new Date(dateString);
        return dateString ;
    } else {
        var dateString = month + "/" + day + "/" + year + " " + hours + ":" + minutes + " " + "AM";

        return dateString;

    }
}

As you can see how it gives back a string. But when I want to covert it to a date with this function. I get this format Fri May 11 2012 09:37:00 GMT+0200 (Romance Daylight Time)

date = new Date(dateString);

And with this I can’t calculate.

Could anybody help me how I can get the current date in this format so that I can do the check?

Kind regards.

  • 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-03T15:11:37+00:00Added an answer on June 3, 2026 at 3:11 pm

    Javascript provides very limited functionality for working with dates out of the box. Use an external library like momentjs.

    For example, your function would be reduced to

    var stringDate = moment().format("DD/MM/YYYY HH:mm A");
    

    And you could convert that and compare it to the current time with

    var earlierDate = moment(stringDate, "DD/MM/YYYY HH:mm A");
    if (earlierDate.valueOf() < moment().valueOf()) {
        // earlier indeed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay... So, I came across the following problem: I have one table that works
Okay so i have a semi weridish problem with re.sub. Take the following code:
i have the following problem with that code in my html tag: <div id=searchbar><input
Okay I have a table that looks as following: id | status(bool) | devicename(text)
Okay, so i have the following html added to a site using javascript/greasemonkey. (just
Okay, at the moment I have the following in my model: has_many :current_monitorings, :class_name
Okay here's my situation. I have the following branches development development-kirby (270 commits ahead
Okay I have a large CRUD app that uses tabs with Forms embedded in
Okay, so I have this problem with my Fact Table. I need it to
I have a problem with reading empty string in C. I want to read

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.