How to Set Current Date and Time in HTML Input by php

How to Set Current Date and Time in HTML Input by php

Sometimes there is a need to set the current date or time in input like in inquiry form, registration form, fee receipt form. We can easily set the current date and time in PHP by using some simple steps. Here are some steps following:

Solution : 

Step1 : echo (new DateTime())->format('Y-m-d'); paste this code in html input value like this :

<input type="date" value="<?php echo (new DateTime())->format('Y-m-d'); ?>">


Step2 : echo (new DateTime())->format('H:i:s'); paste this code in html input value like this :

<input type="date" value="<?php echo (new DateTime('H:i:s'))->format('Y-m-d'); ?>">

I hope this code will help you enjoy coding

Categories: web development php

Trending Courses

CodeIgniter

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Advance Digital Marketing

Regular : 6 Months

Fastrack : 3 Months

Crash : 2 Months

React JS

Regular : 45 Days

Fastrack : 20 Days

Crash : 7 Days

Laravel

Regular : 45 Days

Fastrack : 20 Days

Crash : 10 Days

Front End Developer

Regular : 7 Month

Fastrack : 4 Month

Crash : 2 Month

Related Blogs

Request For Demo