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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:38:26+00:00 2026-05-24T15:38:26+00:00

I have got a string which is maybe date = 10/08/2011; English time style.

  • 0

I have got a string which is maybe date = "10/08/2011"; English time style.

Its a plain string, so I need to be able to add 1 or 2 days to it.

I have tried a few things but can’t work it out as I am normally a PHP guy not JavaScript.

Any help is greatly appreciated.

Thanks

Lee

UPDATE

Why does this seem to be so hard, i’ve been stuck on this for an hour now….. I want to give the code a plain string which is mm/dd/yyyy – 10/08/2011 and i want back something like 11/08/2011

Why so hard ?? this is why i hate javascript and prefer PHP 🙁

  • 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-24T15:38:26+00:00Added an answer on May 24, 2026 at 3:38 pm

    It’s not all that complex:

    //convert string to date
    var dattmp = "10/08/2011".split('/').reverse().join('/');
    var nwdate =  new Date(dattmp);
    
    // to add 1 day use:
    nwdate.setDate(nwdate.getDate()+1);
    
    //to retrieve the new date use
    [nwdate.getDate(),nwdate.getMonth()+1,nwdate.getFullYear()].join('/');
    
    //all in one:
    function dateAddDays( /*string dd/mm/yyyy*/ datstr, /*int*/ ndays){
      var dattmp = datstr.split('/').reverse().join('/');
      var nwdate =  new Date(dattmp);
      nwdate.setDate(nwdate.getDate() + (ndays || 1));
      return [ zeroPad(nwdate.getDate(), 10)
              ,zeroPad(nwdate.getMonth()+1, 10)
              ,nwdate.getFullYear() ].join('/');
    }
    
    //function to add zero to date/month < 10
    function zeroPad(nr, base){
      var len = (String(base).length - String(nr).length) + 1;
      return len > 0? new Array(len).join('0') + nr : nr;
    }
    
    //examples
    console.log(dateAddDays("10/08/2011"));     //=> 11/08/2011
    console.log(dateAddDays("10/08/2011", -5)); //=> 05/08/2011
    

    if you really want it simple – without using the Date Object:

    console.log( '10/08/2011'
      .split('/')
      .map( (v, i) => i < 1 ? +v + 1 : v)
      .join('/') 
    );

    Here’s a small function to convert a date(-time) string to a Date:

    const log = Logger(document.querySelector(`pre`));
    log(
      `<code>str2Date(\`3/15/2013T12:22\`, \`mdy\`)</code>\n  &gt; ${
        str2Date(`3/15/2013T12:22`, `mdy`)}`,
      `<code>str2Date(\`15-2013-03 12:22\`, \`dym\`)\</code>\n  &gt; ${
        str2Date(`15-2013-03 12:22`, `dym`)}`,
      `<code>str2Date(\`15/3/2013\`, \`dmy\`)</code>\n  &gt; ${
        str2Date(`15/3/2013`, `dmy`)}`,
      `<code>str2Date(\`2013/03/15\`)</code>\n  &gt; ${
        str2Date(`2013/03/15`)}` );
    
    function str2Date(dateStr, ymd = `ymd`) {
      ymd = [...ymd].reduce( (acc, v, i) => ({...acc, [v]: i}), {} );
      const dt = dateStr.split(/[ T]/);
      const [d, t] = [ dt[0].split(/[/-]/), dt[1] ];
      return new Date( `${d[ymd.y]}-${d[ymd.m]}-${d[ymd.d]} ${t || ``}` );
    }
    
    function Logger(logEl) {
      return (...args) => {
        args.forEach(arg =>
          logEl.appendChild(
            Object.assign(document.createElement(`div`), {
              innerHTML: `${arg}`,
              className: `logEntry`
            })
          ))
      };
    }
    body {
      font: normal 12px/16px verdana, arial;
    }
    
    .logEntry {
      margin: 5px 0;
    }
    
    .logEntry:before {
      content: '• ';
      vertical-align: middle;
    }
    
    code {
      background-color: #eee;
      color: green;
      padding: 1px 2px;
    }
    <pre></pre>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function which signature is String -> String -> IO (Maybe String)
So I've got this: date('c') which formats it like so: 2010-08-17T08:55:14-07:00 but I need
I've got a class with many string arrays. I'd like to have one generic
We have got loads of options for php + MySQL + Apache combo... Which
I have got a python script which is creating an ODBC connection. The ODBC
I have a custom Http Handler which manipulates HTTP POST and GET. I got
I've got a situation where I need to have my LINQ to Entities query
I have the following C++ code which I got from google's sparsehash website: #include
I have a text area which I need to prevent from having javascript entered.
I have a class with a method in which a string will be passed.

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.