-4

I am trying to create an HTML code (with minimum code length) to obtain the duration or days left for the project to go live. So if I have end date of the project; I want the HTML code to subtract the current date from the end date and give the duration.

But once it shows "-" values I need to get a message. "The Project is in Delivery." along with the duration in "-".

Can you please help provide a simple HTML code for this requirement?

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

1

HTML is merely a markup language. You will need to use some kind of JavaScript code to accomplish what you want:

var numberOfDaysRemaining=
    Math.round((new Date(year,month-1,day)-new Date())/(24*60*60*1000),0);
document.writeln(numberOfDaysRemaining);

You could include this snippet somewhere in your HTML markup inside a <script type="text/JavaScript">... code here ...</script> section. document.writeln() is generally not considered to be good style anymore though, but for a single output it is probably adequate. See here for a little live demo with two dates:

body {font-family: arial}
<h2>My new project</h2>

<p>25.08.2015: 
<script type="text/JavaScript">
  var did=Math.round((new Date(2015,7,25)-new Date())/(24*60*60*1000),0);
  document.writeln(did>0?'The project launch will be in '+did+' days.'
                        :'The project is in the delivery phase since '+(-did)+' days.');
</script>
</p>
<p>05.08.2015: 
<script type="text/JavaScript">
  var did=Math.round((new Date(2015,7,5)-new Date())/(24*60*60*1000),0);
  document.writeln(did>0?'The project launch will be in '+did+' days.'
                        :'The project is in the delivery phase since '+(-did)+' days.');
</script>
</p>
Carsten Massmann
  • 26,510
  • 2
  • 22
  • 43