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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:19:17+00:00 2026-05-29T04:19:17+00:00

I have the following code to get the current day: var month=new Array(12); month[0]=January;

  • 0

I have the following code to get the current day:

var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";

var d = new Date();
var curr_date;
if (d.getDate() == 1)
{
    curr_date = d.getDate();
}
else
{
    curr_date = d.getDate() - 1;
}

var curr_month = d.getMonth() + 1; //months are zero based
var curr_year = d.getFullYear();
var message_day = curr_year + "_" + curr_month + "_" + curr_date;
var sql_day = month[curr_month - 1].substring(0,3) + curr_date.toString() + curr_year.toString();

if (curr_date == "1")
    {
         document.write(sql_day + " " + message_day);
    }

This is great for getting the current day, but now i need to get the last day of the last month if it is the beginning of a new month.

right now this will produce:

Feb12012 2012_2_1

but what i need output is:

Jan312012 2012_1_31

Thanks

  • 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-29T04:19:18+00:00Added an answer on May 29, 2026 at 4:19 am
    var d=new Date(); // current date
    d.setDate(1); // going to 1st of the month
    d.setHours(-1); // going to last hour before this date even started.
    

    now d contains the last date of the previous month. d.getMonth() and d.getDate() will reflect it.

    This should work on any date api that wraps c time.h.

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

Sidebar

Related Questions

I am using the following code to get the current location,I have added the
I have following code to get different parts of current system Date (10-11-2011 for
So I have the following code: // Get the current user _currentUser = WindowsIdentity.GetCurrent();
I have the following code: // GET: /PlayRoundHole/Create public ActionResult Create(int id) { DB
i have the following code def get(self): date = datetime.date.today() loc_query = Location.all() last_cursor
I have the following code making a GET request on a URL: $('#searchButton').click(function() {
I have written a following code to get just the file name without extension
I have the following code in a view to get some of the information
I have the following code : std::string Utils::get() { std::string result; result.append(1, 'x'); result.append(1,
I have the following code and I am still unable to get Hibernate to

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.