-1

I want to know how i can show or get only two numbers Date of current day date in Javascript,

So i can make same if else statements in javascript, for example like this in php

$dt = date("d"); if ( $dt < 10) {then do this} or if ( $dt > 20) {then do this.} 

in php i get this 2 numbers current date with this simple command

echo date("d"); 

Anyone help me out how i can get this in javascript.

0

1 Answer 1

2

The simplest you could do is to use Date.prototype.getDate() :

const d = new Date().getDate(); if (d <= 10) { console.log(`Date is: ${d}. Do this`); } else if (d >= 20) { console.log(`Date is: ${d}. Do something else`); }

Or you could opt for using date libraries like date-fns, moment.js or any other - for better timezone handling.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.