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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:39:06+00:00 2026-05-27T23:39:06+00:00

I am totally new to javascript and I have a very easy to answer

  • 0

I am totally new to javascript and I have a very easy to answer question: How do I use a current year string?

Should I look like this?

var currentyear = now.getYear();

And then I want to use that string in the following code snippet (The string should always replace the 2011)

drawDayEvents('2011-12-27', '#day1');
drawDayEvents('2011-12-28', '#day2');
drawDayEvents('2011-12-29', '#day3');
drawDayEvents('2011-12-30', '#day4');

...

var start = new Date(2011, 12-1, 27);
var end = new Date(2011, 12-1, 31);
if((time < start) || (time > end)) {
time.setYear(2011);

Does it has to be like this?

var currentyear = now.getYear();

drawDayEvents('$currentyear-12-27', '#day1');
drawDayEvents('$currentyear-12-28', '#day2');
drawDayEvents('$currentyear-12-29', '#day3');
drawDayEvents('$currentyear-12-30', '#day4');

...

var start = new Date($currentyear, 12-1, 27);
var end = new Date($currentyear, 12-1, 31);
if((time < start) || (time > end)) {
time.setYear($currentyear);
  • 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-27T23:39:06+00:00Added an answer on May 27, 2026 at 11:39 pm

    You should use getFullYear() instead because getYear() will return the year minus 1900.

    var currentyear = now.getFullYear();
    

    In this line:

    drawDayEvents('$currentyear-12-27', '#day1');
    

    JavaScript can’t interpolate variables like PHP can. You need to concat the strings.

    drawDayEvents(currentyear+'-12-27', '#day1');
    

    Variables in JavaScript don’t need to be prefixed with $ (they can contain a $ if you want).

    var start = new Date(currentyear, 12-1, 27);
    var end = new Date(currentyear, 12-1, 31);
    if((time < start) || (time > end)) {
      time.setYear(currentyear);
    }
    

    Docs for JavaScript Date: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date

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

Sidebar

Related Questions

I'm totally new in ASP.NET so I think it's an easy question I have.
Probably a dead simple and idiotic question (I'm totally new to javascript): I have
I am absolutely and totally new to rails, so the answer is probably very
I am totally new to SQL . I have a simple select query similar
I am totally new to emacs and is starting to learn how to use
I am totally new to javascript and am probably biting of more than I
I'm very new to both the Mvc framework as well as JavaScript and JQuery.
I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
I'm trying to parse a simple JSON file. I'm very new to javascript, JSON,
I have a JavaScript array of objects like this: box[0] = {...} box[1] =

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.