4

i have a field from my database which is start/end date sample fields is

sample field

start_date   |   end_date
2017-04-19   |   2017-04-23

what i want to do is to display this data to my:

<input type="date" name= "start_date" value="<?php echo $value['start_date']?>">

but what happen is it doesn't display anything... i tried to use

<input type="date" name= "start_date" value="<?php echo date('Y-m-d',strtotime($value["start_date"]))?>">

but it displays a different date which is not from my database.. any suggestion to display the date data from my db to the input type="date" ??

3
  • check this out Hope it works for your case Commented Apr 19, 2017 at 9:09
  • woah nice... its working now...thanks for this... but im a bit confuse with the two between date('Y-m-d') and strftime('%Y-%m-%d') .. but thanks alot. Commented Apr 19, 2017 at 9:17
  • Possible duplicate of how to get date from database to html datepicker Commented Mar 1, 2018 at 13:03

1 Answer 1

4

strtotime is use to format a local time/date according to locale settings
Try like this:-

<input type="date" class="m-wrap" value="<?php echo strftime('%Y-%m-%d',
  strtotime($value['start_date'])); ?>" name="date" />

It will work for you .TO check about strtotime look this

Sign up to request clarification or add additional context in comments.

2 Comments

How to check if date is not set in database? In some records, I have NULL values
Hi @AjinkyaRathod, In this situation, you can check the time and if not present then you can set the current date (i.e echo date("Y-m-d")) .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.