SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
JavaScript
1. JavaScript Tutorial for Beginners — Learn JS from Scratch 2. Where to Put JavaScript Code — Head, Body or .js File 3. JavaScript Output Methods — alert, innerHTML, console.log 4. JavaScript Syntax Explained — Statements & Rules 5. JavaScript Comments — How to Write // and /* */ 6. JavaScript Variables — var, let, const Explained 7. JavaScript Operators — Arithmetic, Comparison, Logical 8. JavaScript Data Types — string, number, object, array 9. JavaScript Functions Tutorial — Parameters & Return Values 10. JavaScript Objects — Properties, Methods & this Keyword 11. JavaScript Scope — Global, Local & Block Scope Explained 12. JavaScript Events — addEventListener with Examples 13. JavaScript Strings — Methods, slice, replace & Templates 14. JavaScript Numbers — parseInt, toFixed, NaN Explained 15. JavaScript Arrays — Create, Read, push, pop & More 16. JavaScript Array Methods — map, filter, forEach, find 17. JavaScript Date Object — new Date(), getFullYear & More 18. JavaScript Math Object — random, round, floor, ceil 19. JavaScript if else — Conditions with Examples 20. JavaScript switch Statement — case, break, default 21. JavaScript for Loop — for, for...of, for...in Examples 22. JavaScript while Loop — while & do...while Explained 23. JavaScript Type Conversion — Number, String, Boolean 24. JavaScript try catch — Error Handling with finally 25. JavaScript JSON — stringify & parse with Examples 26. JavaScript Arrow Functions — => Syntax & this 27. JavaScript Classes — Constructor & Objects Explained 28. JavaScript Promises & async/await Explained Simply 29. JavaScript DOM Tutorial — Find & Change Page Elements 30. JavaScript Form Validation Tutorial with Examples 31. JavaScript Fetch API Tutorial — fetch() with Examples 32. JavaScript localStorage — setItem, getItem Explained 33. JavaScript Timers — setTimeout & setInterval Examples 34. JavaScript Regular Expressions — test() & match() Guide 35. JavaScript Debugging — console.log & Fixing Errors
Final Test — Certificate ₹10
Try this code live
Lesson 17 of 35

JavaScript Date Object — new Date(), getFullYear & More

5 min read · Free · No login needed

Every website deals with dates: exam dates, birthdays, booking days, "posted 3 days ago". JavaScript has a built-in Date object for all of it. You create a date with new Date(), and then you ask it questions: what year is it, what month, what day, what weekday?

Diagram — see how it fits together
Diagram: JavaScript Dates

Think of a date like a wall calendar. new Date() opens the calendar to today. Then getFullYear() reads the year printed at the top, getMonth() tells you which page you are on, getDate() points at today's number, and getDay() tells you whether it is Monday or Sunday. Each question is a small method — and together they let you build anything from a countdown to an admit-card page.

Remember it like this: months count from zero, days count from one. January is month 0, December is month 11 — but the 1st of the month is day 1. That one quirk causes more beginner bugs than anything else about dates.

new Date() — today, right now

new Date() with nothing inside it creates a date for this exact moment — today's date and the current time. The word new matters: it builds a fresh Date object for you.

let today = new Date();
console.log(today);
// Something like: Wed Oct 28 2026 20:15:00 GMT+0530

You can also build a date for a specific day by passing the year, month and day: new Date(2026, 10, 15) means 15 November 2026. Watch out — the month is 0-based, so November is 10, not 11. January is 0, February is 1, and December is 11.

getFullYear, getMonth, getDate — reading a date

These three methods read the parts of a date. They are the ones you will use most.

let exam = new Date(2026, 10, 15);
exam.getFullYear(); // 2026
exam.getMonth();    // 10 (November — months start at 0)
exam.getDate();     // 15 (the day of the month)

getFullYear() gives all four digits — 2026, not 26. There is also an old method called getYear() that gives a strange number; never use it. Always use getFullYear().

Note: Months start at 0 but days start at 1. So new Date(2026, 0, 1) is 1 January 2026, and new Date(2026, 11, 31) is 31 December 2026. When you show a month to a user, add 1 first: exam.getMonth() + 1 gives 11 for November.

getDay — which weekday is it?

getDay() returns a number from 0 to 6. Sunday is 0, Monday is 1, and Saturday is 6. It is handy when you want to say "exam on Monday" or check whether today is a weekend.

let days = ["Sunday", "Monday", "Tuesday", "Wednesday",
            "Thursday", "Friday", "Saturday"];
let today = new Date();
let weekday = days[today.getDay()];
// "Wednesday" (if today is a Wednesday)

The trick is a small array of weekday names, and getDay() picks the right one. The same trick works for months: keep an array of twelve month names and let getMonth() pick one.

toDateString — a readable date

A raw Date object prints as a long ugly line with the time and timezone. toDateString() gives you a short, human-readable version: just the weekday, month, day and year.

let exam = new Date(2026, 10, 15);
exam.toDateString();
// "Sun Nov 15 2026"

There are more formats too: toLocaleDateString() gives the date in the user's own style (15/11/2026 in India), and toISOString() gives the standard 2026-11-15 format that computers prefer. For showing a date to a student, toDateString() is usually the clearest.

Common mistakes

  • Forgetting that months are 0-based — writing new Date(2026, 11, 15) for November gives you December. November is month 10.
  • Using getYear() instead of getFullYear() — the old one returns a useless number like 126. Always use getFullYear().
  • Mixing up getDate() and getDay() — getDate() is the day of the month (1–31), getDay() is the weekday (0–6).
  • Showing getMonth() directly to a user — it prints 0 for January. Add 1 when you display it.
  • Forgetting the word new — Date() without new just returns a text string, not a Date object, so none of the methods work on it.

Remember

  • Months count from zero, days count from one. January is 0, the 1st is 1.
  • new Date() is today; new Date(2026, 10, 15) is 15 November 2026.
  • getFullYear(), getMonth(), getDate() read the parts; getDay() gives the weekday (Sunday is 0).
  • toDateString() turns a date into readable text like "Sun Nov 15 2026".

Example explained

  • let exam = new Date(2026, 10, 15); — builds the exam date, 15 November 2026. The month is 10 because months count from zero.
  • let days = ["Sunday", "Monday", ...]; — an array of weekday names, so the number from getDay() can be turned into a word.
  • days[exam.getDay()] — getDay() returns 0 for Sunday, so this picks "Sunday" from the array.
  • exam.toDateString() — gives the short readable form "Sun Nov 15 2026".
  • document.getElementById("result").innerHTML = ... — writes the exam date and weekday into the page when the button is clicked.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Exam Date — JavaScript Dates</title>
<style>
body { font-family: Verdana, sans-serif; padding: 20px; }
h1 { color: #1e3a5f; }
button { background-color: #e13611; color: white; border: none; padding: 10px 18px; font-size: 16px; cursor: pointer; }
p { font-size: 18px; }
.result { background-color: #f1f5f9; padding: 12px; }
</style>
</head>
<body>

<h1>BTEUP Exam Date</h1>
<p>Odd semester theory exams start soon.</p>
<button onclick="showExamDate()">Show Exam Date</button>
<p class="result" id="result">Click the button to see the exam date and weekday.</p>

<script>
function showExamDate() {
  let exam = new Date(2026, 10, 15);
  let days = ["Sunday", "Monday", "Tuesday", "Wednesday",
              "Thursday", "Friday", "Saturday"];
  let weekday = days[exam.getDay()];
  document.getElementById("result").innerHTML =
    "Exam date: " + exam.toDateString() +
    "<br>Day: " + weekday +
    "<br>Year: " + exam.getFullYear();
}
</script>

</body>
</html>

Output

Output — how it looks in the browser
Output of JavaScript Date Object — new Date(), getFullYear & More

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. How do I get today's date in JavaScript?

Use new Date() with nothing inside it — it creates a date for this exact moment, with the current time.

2. Why is January month 0 in JavaScript?

Months count from zero, so January is 0 and December is 11 — but days of the month count from one.

3. How do I build a date for a specific day?

Pass year, month and day to the constructor, like new Date(2026, 10, 15) — remembering the month is zero-based.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

Full Stack PHP Development Course 2026
₹3,000
View
Website Design Using WordPress 3 Days (Basic to Advanced)
₹199
View
Android & iOS App Development using Flutter 2026
₹5,000
View
Browse all courses
JavaScript — Lessons
1. JavaScript Tutorial for Beginners — Learn JS from Scratch 2. Where to Put JavaScript Code — Head, Body or .js File 3. JavaScript Output Methods — alert, innerHTML, console.log 4. JavaScript Syntax Explained — Statements & Rules 5. JavaScript Comments — How to Write // and /* */ 6. JavaScript Variables — var, let, const Explained 7. JavaScript Operators — Arithmetic, Comparison, Logical 8. JavaScript Data Types — string, number, object, array 9. JavaScript Functions Tutorial — Parameters & Return Values 10. JavaScript Objects — Properties, Methods & this Keyword 11. JavaScript Scope — Global, Local & Block Scope Explained 12. JavaScript Events — addEventListener with Examples 13. JavaScript Strings — Methods, slice, replace & Templates 14. JavaScript Numbers — parseInt, toFixed, NaN Explained 15. JavaScript Arrays — Create, Read, push, pop & More 16. JavaScript Array Methods — map, filter, forEach, find 17. JavaScript Date Object — new Date(), getFullYear & More 18. JavaScript Math Object — random, round, floor, ceil 19. JavaScript if else — Conditions with Examples 20. JavaScript switch Statement — case, break, default 21. JavaScript for Loop — for, for...of, for...in Examples 22. JavaScript while Loop — while & do...while Explained 23. JavaScript Type Conversion — Number, String, Boolean 24. JavaScript try catch — Error Handling with finally 25. JavaScript JSON — stringify & parse with Examples 26. JavaScript Arrow Functions — => Syntax & this 27. JavaScript Classes — Constructor & Objects Explained 28. JavaScript Promises & async/await Explained Simply 29. JavaScript DOM Tutorial — Find & Change Page Elements 30. JavaScript Form Validation Tutorial with Examples 31. JavaScript Fetch API Tutorial — fetch() with Examples 32. JavaScript localStorage — setItem, getItem Explained 33. JavaScript Timers — setTimeout & setInterval Examples 34. JavaScript Regular Expressions — test() & match() Guide 35. JavaScript Debugging — console.log & Fixing Errors
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →