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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:11:04+00:00 2026-06-15T00:11:04+00:00

What I am trying to achieve is when I input a date into this

  • 0

What I am trying to achieve is when I input a date into this function, it should give me this:

If the date is:

Today – output as Today
Tomorrow – output as Tomorrow
Yesterday – output as Yesterday

Else – output as “Month – Day” format

But I can’t get this to work. Any help? JsFiddle here.

//My Date variable
var mydate = "22-Nov-2012"

alert(MDFormat(mydate));

/*
If the date is:
    Today - show as "Today";
    Tomorrow - show as "Tomorrow"
    Yesterday - show as "Yesterday"
    Else - show in "Month - Day format"
*/
function MDFormat(MMDD) {
    MMDD= new Date(MMDD);
    var months = ["Jan", "Feb", "Mar", "Apr", "May", "June", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
    var day = MMDD.getDate();
    var month = months[MMDD.getMonth()];

    var currentDay = new Date().getDay();
    var today;
    if (currentDay == MMDD.getDay()) {
        today = MMDD.getDay();
    } 
    var tmr = currentDay + 1; 
    var yest = currentDay - 1; 

    var strDate;

    switch (MMDD) {
        case today:
            strDate = "Today";
            break;
        case tmr:
            strDate = "Tomorrow";
            break;
        case yest:
            strDate = "Yesterday";
            break;
        default:
            strDate = month + "-" + day;
            break;
    }

    return strDate;
}​

Note: I prefer a plugin-less way.

  • 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-15T00:11:05+00:00Added an answer on June 15, 2026 at 12:11 am

    getDate only works on valid predefined date formats. The one you are using is not a valid predefined format. If you try this:

    var mydate = "Nov 22, 2012";
    alert(MDFormat(mydate));
    

    it works.

    Also took the liberty of fixing up a few problems with your logic:

    //My Date variable
    var mydate = "Nov 22, 2012"
    
    alert(MDFormat(mydate));
    
    
    /*
    If the date is:
        Today - show as "Today";
        Tomorrow - show as "Tomorrow"
        Yesterday - show as "Yesterday"
        Else - show in "Month - Day format"
    */
    
    function MDFormat(MMDD) {
        MMDD = new Date(MMDD);
    
        var months = ["Jan", "Feb", "Mar", "Apr", "May", "June", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
        var strDate = "";
    
        var today = new Date();
        today.setHours(0, 0, 0, 0);
    
        var yesterday = new Date();
        yesterday.setHours(0, 0, 0, 0);
        yesterday.setDate(yesterday.getDate() - 1);
    
        var tomorrow = new Date();
        tomorrow.setHours(0, 0, 0, 0);
        tomorrow.setDate(tomorrow.getDate() + 1);
    
        console.log(MMDD.getTime(),today.getTime(),MMDD.getTime()==today.getTime());
    
        if (today.getTime() == MMDD.getTime()) {
            strDate = "Today";
        } else if (yesterday.getTime() == MMDD.getTime()) {
            strDate = "Yesterday";
        } else if (tomorrow.getTime() == MMDD.getTime()) {
            strDate = "Tomorrow";
        } else {
            strDate = months[MMDD.getMonth()] + "-" + MMDD.getDate();
        }
    
        return strDate;
    }
    

    Demonstration: http://jsfiddle.net/xqnc8/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to achieve this: <label ...>First name<em>*</em></label> <input ... /> with this: <%=
I am trying to achieve something like this. The Expandable List consists of the
im trying to achieve the following, in php i have a form like this:
Here's what I'm trying to achieve: This is the HTML code I wrote: <div
in my application, i'm trying to achieve something like this: i have: data 0,
I'm trying to achieve a layout in html that looks exactly like this when
iam trying to achieve this exact functionalty: http://jsfiddle.net/exttq/ BUT inside using my PHP, right
I'm trying to achieve a two way binding between an input field and a
I'm trying to fire a function when the keyup event happens. This works fine
I am trying to validate input date fields, and I want to make sure

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.