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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:05:21+00:00 2026-05-13T20:05:21+00:00

I have an string that contains month/date and I need to insert the year.

  • 0

I have an string that contains month/date and I need to insert the year. The string looks like:

Last Mark:: 2/27 6:57 PM

I want to convert the string to something like:

Last Mark:: 2010/02/27 18:57

In this case, there will not be any entries more than a year old. For example, if the date were 10/12 it can be assumed that the year is 2009.

What is the best method for this?

  • 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-13T20:05:21+00:00Added an answer on May 13, 2026 at 8:05 pm

    Following from Adam’s suggestion:

    function convertDate(yourDate) {
       var today = new Date();
       var newDate = new Date(today.getFullYear() + '/' + yourDate);
    
       // If newDate is in the future, subtract 1 from year
       if (newDate > today) 
           newDate.setFullYear(newDate.getFullYear() - 1);
    
       // Get the month and day value from newDate
       var month = newDate.getMonth() + 1;
       var day = newDate.getDate();
    
       // Add the 0 padding to months and days smaller than 10
       month = month < 10 ? '0' + month : month;     
       day = day < 10 ? '0' + day : day;
    
       // Return a string in YYYY/MM/DD HH:MM format
       return newDate.getFullYear() + '/' +
              month + '/' +
              day + ' ' +
              newDate.getHours() + ':' +
              newDate.getMinutes();
    }
    
    convertDate('2/27 6:57 PM');  // Returns: "2010/02/27 18:57"
    convertDate('3/27 6:57 PM');  // Returns: "2009/03/27 18:57"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that contains ampersands. I need to escape each ampersand in
I have a query string that contains a variable like this $field_name = 'features';
I have a string that contains a date, in the following format: dd-mm-yyyy with
I have a table that contains only Month and Year field both as int.
I have a array that contains all the months in a year like so:
I have a string strDate that contains selected date. strDate holds value in the
I have a string that contains HTML image elements that is stored in a
I have a string that contains a known number of double values. What's the
I have a string that contains a czech character. the string is 0bálka This
If I have a string that contains a url (for examples sake, we'll call

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.