Home » Search results for 'javascript date'

Compare JavaScript Dates (Day/Minute/Hour/Before/After), With Examples

JavaScript Compare Dates

Following on from our article on adding and subtracting time from dates in JavaScript – here’s how to compare two JavaScript date objects. This article will explore comparing dates/times with different granularity levels – from dates that are an exact month to dates that fall in the same year. Using Boolean Operators Native Javascript date objects can be compared using standard boolean/comparison operators – allowing you to compare dates by checking whether they are equal, not equal, greater than, less than, equal to or greater than, or equal to or … Read more

Home » Search results for 'javascript date'

Add Days (or Minutes, or Hours) to Javascript Date [or Subtract]

Add Days to Javascript Date

This article will explain how to add (or subtract) days, minutes, hours, seconds (etc.) to a JavaScript date. Why would you want to do this? Perhaps you want to tell a user that their assignment is due in a week and provide the date, or maybe your application needs to know what the date was 30 days ago to pop up a reminder – there are near-infinite usage cases. Add Days to Date Using Vanilla JavaScript First, here’s how it’s done in plain old JavaScript: … Read more

Home » Search results for 'javascript date'

Check/Validate String Matches Regex in JavaScript [Examples]

JavaScript regex match

This article will show you how to use Regular Expressions (Regex) to validate matching strings in JavaScript. All user input collected in your applications should be validated. If an email address is required, a valid email address should be entered, or sending the email will fail. If a phone number is required, a valid phone number must be entered, and so on. Regex can be used for this validation by matching a whole string to a specified format. Regex can also be used to search … Read more

Home » Search results for 'javascript date'

How to Get the Current Date and Time in JavaScript

JavaScript get current date/time

This article will show you how to get the current date, time, or both, in the JavaScript programming language. Code examples included. Date Objects in JavaScript Date objects represent a single point in time in JavaScript. They are created by initializing a new variable with a new Date object: var now = new Date(); By default, new Date objects are initialized to contain the date and time at the instant they were created, along with timezone details for the current device – thus representing the current … Read more

Home » Search results for 'javascript date'

How to Convert String to Date in JavaScript, With Examples

JavaScript String to Date

Here are some easy-to-understand methods for converting strings to date objects in the JavaScript Programming language. Looking to compare dates in JavaScript? Find out how here. The Hard Way – Using Vanilla JavaScript JavaScript contains built-in functions for parsing a date from a string – but it’s severely limited. So here it is in action: var myString = ’01 Jan 1970 00:00:00 GMT’; var myDate = new Date(Date.parse(myString)); What’s happening here? A string is defined containing a date. A new Date object is then defined using the … Read more

Home » Search results for 'javascript date'

JavaScript Reference: Complete List of Operators + Examples

JavaScript Operators

This article will explain and list JavaScript operators and expressions. JavaScript operators perform a given operation on the provided expressions or values. Common operations include comparisons, arithmetic, and ternary operations. You will use JavaScript operators frequently (even the simplest JavaScript code will use multiple operators!), so it’s worth getting to know them, and their expected behaviour. What are Operators and Operands? Javascript operators perform a given operation, for example addition, subtraction, and other arithmetic, comparisons like greater than/less than, and more complicated operations like ternary/comparison … Read more

Home » Search results for 'javascript date'

Checking for Equality (And Inequality) in JavaScript, with Examples

Equality and Inequality JavaScript

This article will explain equality and inequality in the JavaScript Programming language, and provide code examples showing how to check if values are equal in value and type. Checking whether two values are equal can get a bit confusing in JavaScript – there is loose equality and strict equality involving types to consider. Read on to find out how testing for equality and inequality works in JavaScript. What are equality and inequality? In programming, equality is the process of checking whether two values are equal … Read more

Home » Search results for 'javascript date'

The JavaScript valueOf() Method – What Does it Actually Do?

JavaScript valueOf()

This quick tutorial will explain the JavaScript valueOf() Method, what it does, and why you might use it. The JavaScript valueOf() method gets the primitive value of the object it is called from. Usually you will not need to call it, however it does have its use cases. Primitives vs Objects In JavaScript, a value or variable has a type of value. A primitive is a value that is not an object, with no methods or properties, representing only the data that it exists as. JavaScript has 7 primitive data types: string number bigint boolean undefined … Read more

Home » Search results for 'javascript date'

for…in Loops in JavaScript – How to Use Them

JavaScript for...in loop

The for…in loop in JavaScript loops over all of the properties in an object. This article will explain why and how to use it. JavaScript Objects JavaScript objects are a kind of variable which store the properties for an item you are representing in your code. For example, you may have a car object, which of which the make, year, model, and colour of a car are it’s properties. Each car object would have it’s own separate list of properties which define that car. JavaScript objects can also be used as hash tables – providing … Read more

Home » Search results for 'javascript date'

Remove Page Elements using JavaScript RemoveChild [Examples]

JavaScript removeChild()

The Node.removeChild() method removes HTML Element from the current page via the DOM. This article will show you how to use it. The DOM in JavaScript The HTML DOM (Document Object Model) is the interface which JavaScript uses to interact with HTML page elements, including adding, removing, and modifying on-screen items. It is the data structure which represents every HTML tag present on a page – everything from the root <html> element that wraps the page to every <div>, <p>, <input>, and <span> – everything on the page is represented in the DOM, both … Read more