JavaScript getDate Function

JavaScript getDate function is one of the Date Functions, which is useful to return the Day number from a given. This article shows how to use Get Date in JavaScript Programming with an example.

JavaScript getDate Function Example

The following example helps you understand the get Date Function. Here, we are using getDate to return the date from the current datetime.

<!DOCTYPE html>
<html>
<head>
    <title> JFunctions </title>
</head>
<body>
    <h1> Example </h1>
<script>
  var dt = Date();  
  document.write("DateTime : " + dt);
  document.write("Date : " + dt.getDate());
</script>
</body>
</html>
Example

DateTime: Sat Nov 03 2018 15:34:10 GMT+0530 (Indian Standard Time)
Date : 3

getDate Example 2

In this JavaScript example, we are extracting the date numbers from the custom datetime.

<!DOCTYPE html>
<html>
<head>
    <title> JS </title>
</head>
<body>
    <h1> JavaScriptgetDateFunction Example </h1>
<script>
  var dt = Date("January 22, 2014 10:09:07");
  document.write("Date and Time : " + dt);
  document.write("Date from getDate(): " + dt.getDate());
</script>
</body>
</html>
JavaScript getDate Function Example