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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:25:58+00:00 2026-06-05T14:25:58+00:00

I want to create two dates that contain the beginning date of a month

  • 0

I want to create two dates that contain the beginning date of a month and the beginning date of the following month. This is what I have:

var TheMonth = "6.2012"; // as in june 2012
TheMonth = TheMonth.split(".")

var TheDisplayDate = new Date(parseInt(TheMonth[1], 10), (parseInt(TheMonth[0], 10) - 1), 1);

var TheUpperLimit = new Date(TheDisplayDate.getFullYear(), TheDisplayDate.getMonth(), 1);

//I'm adding a month here but it's not changing the month
TheUpperLimit.setMonth(TheUpperLimit.getUTCMonth() + 1);

The problem is that TheUpperLimit turns out to be the same date. I have a fiddle here to look at.
What am I doing wrong?

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-06-05T14:26:00+00:00Added an answer on June 5, 2026 at 2:26 pm

    The problem is that you use getUTCMonth with setMonth instead of setUTCMonth. It’s more correct to use only UTC or only non-UTC methods together. When you use setMonth and getMonth, it seems to work correct. But when you use UTC variations of these functions, it gives you 2 jul instead of 1 jul (in my time zone, at least). I suggest you to use the following code to avoid complications with time:

    var TheMonth = "6.2012"; // as in june 2012
    TheMonth = TheMonth.split(".");
    var month = parseInt(TheMonth[0]);
    var year = parseInt(TheMonth[1]);
    var second_month = month + 1;
    var second_year = year;
    if (second_month > 12) {
        second_month = 1;
        second_year++;
    }
    
    var TheDisplayDate = new Date(year, month - 1, 1);
    var TheUpperLimit = new Date(second_year, second_month - 1, 1);
    console.log([TheDisplayDate, TheUpperLimit]);
    // => [Date {Fri Jun 01 2012 00:00:00 GMT+0400 (MSK)}, 
    //     Date {Sun Jul 01 2012 00:00:00 GMT+0400 (MSK)}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a view from the following two tables: Entry: entry_id entry_date
I want to create two widgets in flex. One for the movies ( that
I have a state column in a dataframe and I want to create two
i have two tables Order(id, date, note) and Delivery(Id, Note, Date) I want to
I have a situation where I want to connect two tables that do not
I want to create two date stamps, one for OK and one for NOT
I have a couple of textboxes that will contain dates only. If one textbox
I have two arrays: var columns = ["Date", "Number", "Size", "Location", "Age"]; var rows
I want to parse this Json code : [{id:7,key:integrationContinue:integrationContinue,name:life Portlet,scope:PRJ,qualifier:TRK,date:2012-03-26T10:10:22+0100,lname:life Portlet,lang:java,version:1.0-SNAPSHOT,description:,msr:[{key:ncloc,val:897.0,frmt_val:897},{key:coverage,val:0.6,frmt_val:0,6%}]}] I created two
I want to create two equal timestamps for a given day in PHP and

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.