---
title: "Entering current date in existing html control by using java script"  
description: "In this demonstration I will tell you that how to display date with different format and enter it in an existing html control like  (paragraph).  Writ"  
author: "Anonymous User"  
published: 2011-03-13  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/491/entering-current-date-in-existing-html-control-by-using-java-script  
category: "javascript"  
tags: ["javascript"]  
reading_time: 1 minute  

---

# Entering current date in existing html control by using java script

In this demonstration I will tell you that how to display date with different format and enter it in an existing html control like <p> (paragraph).\

Write down following code snippet in notepad and save it with .html extension.

##### Code:

```
<html xmlns="http://www.w3.org/1999/xhtml"><head>     <title></title>     <script type="text/javascript">        function displayDate() {            var now = new Date();            var message =  "For MM/DD/YYYY format <br />";            var mdyFormat = now.getMonth() + "/" + now.getDate() + "/" + now.getYear();            message = message + mdyFormat + "<br />";            message = message + "For DD/MM/YYYY format <br />";            mdyFormat = now.getDate() + "/" + now.getMonth() + "/" + now.getYear() + "<br />";            message = message + mdyFormat + "For YYYY/MM/DD format <br />";            mdyFormat = now.getYear() + "/" + now.getMonth() + "/" + now.getDate();            message = message + mdyFormat;            document.getElementById('datedemo').innerHTML = message;                    }     </script></head><body>     <h1>Date Demonstration.</h1>     <p id="datedemo">             </p><br />     <input type="button" value="Display Date" onclick="displayDate()" /></body></html>
```

##### Output of the following code snippet is as follows

![Current date in existing html control using java script](https://www.mindstick.com/mindstickarticle/74a106c6-47ae-4b02-9f77-2fab0de00061/images/8cef245c-27d6-4f3b-b6af-26fc4867580f.png)

---

Original Source: https://www.mindstick.com/articles/491/entering-current-date-in-existing-html-control-by-using-java-script

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
