I need to convert the date that I am getting from an HTML5 date input to a timestamp and save it as a variable.
HTML:
<form>
<section class="input">
<input type="date" id="date" name="maintenanace_date"/>
</section>
<section class="input">
<input type="time" id="time" name="maintenance_time" placeholder="EST"/>
</section>
</form>
var date = new Date(document.getElementById("time").value);
var timestamp = date.getTime();
If you need to use it in a serverside language like PHP, you also need to divide it by 1000.
However, this depends on the format the date is entered in. If you're using a non-default date format, you'll need to split it up and convert it into year, month and date before instantiating the Date object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With