0

PHP 5.3

Friends, I'm trying to insert the current date into an input, but it's not right, what do I do?

I tried everything and I can not find a solution, but in a normal echo it prints the input. The only "error" that is that warning in the browser console. The specified value "13-06-2019" does not conform to the required format, "yyyy-MM-dd".

In the beginning the page has:

<?php date_default_timezone_set('America/Sao_Paulo'); ?>

Prints: https://i.sstatic.net/0mG1g.jpg

<?php $actualDate = date('d-m-Y'); echo $actualDate.' | '.date('Y-m-d');?>
<input type="date" class="form-control" name="dateRegister" id="dateRegister" value="<?php echo $actualDate; ?>" readonly>
<input type="text" class="form-control" name="dateRegister" id="dateRegister" value="<?php echo $actualDate; ?>" readonly>
<input type="date" class="form-control" name="dateRegister" id="dateRegister" value="<?php echo date('Y-m-d'); ?>" readonly>
<input type="text" class="form-control" name="dateRegister" id="dateRegister" value="<?php echo date('Y-m-d'); ?>" readonly>

[Warning]

The specified value "13-06-2019" does not conform to the required format, "yyyy-MM-dd".

4
  • Look closely at $actualDate = date('d-m-Y'). What do you expect the date format string "d-m-Y" to produce? Commented Jun 13, 2019 at 23:39
  • @Phil Even with Y-m-d does not work. Commented Jun 13, 2019 at 23:58
  • Prove it! Show what you've changed by updating your question Commented Jun 13, 2019 at 23:59
  • Small Note PHP5.3 has no friends. It reached end-of-life 5 years ago. Can you not upgrade? Commented Jun 14, 2019 at 1:03

1 Answer 1

1

Your code prints the value 13-06-2019 but requires a yyyy-MM-dd format.

Instead of $actualDate = date('d-m-Y') you need to set $actualDate = date('yyyy-MM-dd').

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

3 Comments

Yeah, that's not how PHP's date() function works ~ 3v4l.org/6j2HH
Not work with date('yyyy-MM-dd'); He print 19191919-JunJun-1414
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.