Shujaat Shaikh
Shujaat Shaikh

Reputation: 299

Preset current date and time in input type "datetime" using php

How can I preset the value in datetime input to current date and time using php or javascript?

<input type="datetime-local" name="followupon">

What I have.. enter image description here

What I want... **enter image description here**

Upvotes: 0

Views: 4190

Answers (1)

Wessel van der Linden
Wessel van der Linden

Reputation: 2622

Well.. You can just set the value by using the "value" attribute:

<input type="datetime-local" name="followupon" value="2014-01-02T11:42:13.510">

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local#Value for more information

If you want to use the current date, you can use php like so:

<input type="datetime-local" name="followupon" value=<?php echo date('Y-m-d\TH:i:s'); ?>">

Upvotes: 6

Related Questions