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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:08:18+00:00 2026-05-30T21:08:18+00:00

I pick this date from a textbox and i would like to format to

  • 0

I pick this date from a textbox and i would like to format to this format: yyyy-MM-dd
So from dd/MM/yyyy to yyyy-MM-dd

 var startDate = document.getElementById('ctl00_PlaceHolderMain_ctl00_Date').value;
    var s = new Date(startDate);
    alert(startDate); //which prints out 7/03/2012
    //when i use the below to try and format it to : yyyy-MM-dd which is what i want
    var scurr_date = s.getDate();
    var scurr_month = s.getMonth();
    scurr_month++;
    var scurr_year = s.getFullYear();

For some reason i get:

var fstartdate = scurr_year + "-" + scurr_month + "-" + scurr_date;
//Output:2012-7-3
instead of : 2012-3-7
also fi i pick a date like 31/12/2011
i get : 2013-7-12

Any ideas what to do.I kind of notice if i use US like 03/07/2012 it kind os works ok.
Thank in advance

  • 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-30T21:08:19+00:00Added an answer on May 30, 2026 at 9:08 pm

    You said you want to convert from “dd/MM/yyyy to yyyy-MM-dd”. JavaScript’s Date constructor will always take the first two digits as a month.

    Some regex might help you here:

    function fix_date (str) {
        var re = /(\d{1,2})\/(\d{1,2})\/(\d{4})/;
        str = str.replace(re, function (p1, p2, p3, p4) {
            return p4 + '/' + p3 + '/' + p2;        
        });
    
        return str;
    }
    
    var start_date = '7/03/2012';
    var new_date = fix_date(start_date);
    
    console.log(new_date); // 2012/03/7​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my date format is like 2010-11-15 04:28:31 i want to pick just 2010-11-15 instead
I've got this: var lDate = document.getElementById('txtLeaveDate'); var rDate = document.getElementById('txtReturnedDate'); Err...javascript so how
I need to validate this simple pick list: <select name=<%= key %>> <option value=ETC
After reading this answer: best way to pick a random subset from a collection?
OK, this is minefield, but trying to understand why one would pick .NET (or
Basically I'm using datepicker from jQuery to have my client pick a date. I
How do I pick a random element from a set? I'm particularly interested in
I need to pick up list items from an list, and then perform operations
How do I pick/ delete all the documents from Solr using the boolean NOT
I'm trying to get the date from a datepicker on a dialog. But it's

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.