# Intercept Date Fields on save

**URL:** <https://discourse.cakephp.org/t/intercept-date-fields-on-save/4968>\
**Category:** Need Help\
**Created:** [September 20, 2018, 5:31pm UTC](https://discourse.cakephp.org/t/intercept-date-fields-on-save/4968 "2018-09-20T17:31:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhall](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jhall](https://discourse.cakephp.org/u/jhall)\
**Post date:** [September 20, 2018, 5:31pm UTC](https://discourse.cakephp.org/t/intercept-date-fields-on-save/4968/1 "2018-09-20T17:31:29Z")

</div>

I am using the built in JQuery datepicker on some of my controls in my view and I would like them to display as mm-dd-yyyy but mysql expects them in a different format which causes an error. How to solve this?

---

<div class="post-metadata">

**Author:** ![jhall](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jhall](https://discourse.cakephp.org/u/jhall)\
**Post date:** [September 20, 2018, 6:44pm UTC](https://discourse.cakephp.org/t/intercept-date-fields-on-save/4968/2 "2018-09-20T18:44:17Z")

</div>

I ended up using the altformat and altfield properties of the datepicker module and this seems to be working

---

<div class="post-metadata">

**Author:** ![bird](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bird/32/1157_2.png) [@bird](https://discourse.cakephp.org/u/bird)\
**Post date:** [September 20, 2018, 6:44pm UTC](https://discourse.cakephp.org/t/intercept-date-fields-on-save/4968/3 "2018-09-20T18:44:19Z")

</div>

You can handle this with the beforeMarshal event in cakephp see: [https://book.cakephp.org/3.0/en/orm/saving-data.html#before-marshal](https://book.cakephp.org/3.0/en/orm/saving-data.html#before-marshal)

You could also use mysqls STR\_TO\_DATE which i don’t reccomend: [https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function\_str-to-date](https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_str-to-date)

Or you could transform your data on the client side with altForm: [http://api.jqueryui.com/datepicker/#option-altFormat](http://api.jqueryui.com/datepicker/#option-altFormat)

---

<div class="post-metadata">

**Author:** ![jhall](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jhall](https://discourse.cakephp.org/u/jhall)\
**Post date:** [September 20, 2018, 6:44pm UTC](https://discourse.cakephp.org/t/intercept-date-fields-on-save/4968/4 "2018-09-20T18:44:47Z")

</div>

The last one you mentioned is the one I ended up doing Thanks so much
