I have a plugin that includes a datepicker.

I initialize the datepicker like this


    'format': 'mm/dd/yyyy',
    'todayHighlight': true

I am saving the date from my plugin like this:

$myDate = craft()->request->getPost('myDate');
if ($myDate) {
    DateTime::createFromString($myDate, craft()->timezone);

$fieldsLocation = craft()->request->getParam('fieldsLocation', 'fields');

Because I have designated this field to be required, I get an error back saying that the field cannot be blank. Even though I have chosen a date.

If I change my datepicker to use this format:

    'format': 'yyyy/mm/dd',
    'todayHighlight': true

Everything works. I like how "human/U.S" friendly the top example is vs. yyyy-mm-dd.

Since I am populating the entry with this:


Is there a way to convert what is passed in to the correct format Craft is looking for?

I've tried something like:

$date = date(str_replace('/', '-', craft()->request->getPost('myDate')));

$myDate = date('Y-m-d', strtotime($date));

But that is getting overwritten by this guy still:


Thank you for any suggestions!

1 Answer 1


After $entry->setContentFromPost($fieldsLocation); you should be able to add another line to explicitly set your calculated date.

$entry->setContent(array('fieldName' => $myDate));

Then just proceed with saving the entry as normal.

  • Thank you! I didn't realize I could call setContent back to back like that.
    – Damon
    Commented Jan 17, 2017 at 11:49

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.