[Skip to main content](#vessel-content)

#   Jalali date (Persian) for simple date picker

##

- **[mahdi.manian](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile")**
- [![mahdi.manian's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile") Topic Author
- [ Offline](/forum/user/38733-mahdi-manian)

Less More

- Posts: 2
- Thank you received: 0
-
-

10 years 3 months ago [\#244810](#244810) by [mahdi.manian](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile")  *[Jalali date (Persian) for simple date picker](/forum/33-customers/885428-jalali-date-persian-for-simple-date-picker#244810 "Hi.  I have a problem with simple date picker custom field (Address). My website language is Persian and i use jalali date in simple date picker, but when i save the address date don't save correctly and when i want to edit this address, date show incorrect.  Please see this pictures:  the problem is jalali date saved to database but this is mistake and jalali date should be convert to original date and then saved to database. and when i edit the address, original date should be convert to jalali and show to me.  Please help me. Thanks you.")* was created by *[mahdi.manian](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile")*

Hi.

I have a problem with simple date picker custom field (Address). My website language is Persian and i use jalali date in simple date picker, but when i save the address date don't save correctly and when i want to edit this address, date show incorrect.

Please see this pictures:
[ ![&#91;img](http://upload.joomiran.com/uploads/05_07_16_1.png) ](http://upload.joomiran.com/uploads/05_07_16_1.png "&#91;img")

[ ![&#91;img](http://upload.joomiran.com/uploads/05_07_16_2.png) ](http://upload.joomiran.com/uploads/05_07_16_2.png "&#91;img")

[ ![&#91;img](http://upload.joomiran.com/uploads/05_07_16_3.png) ](http://upload.joomiran.com/uploads/05_07_16_3.png "&#91;img")

the problem is jalali date saved to database but this is mistake and jalali date should be convert to original date and then saved to database. and when i edit the address, original date should be convert to jalali and show to me.

Please help me. Thanks you.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy84ODU0MjgtamFsYWxpLWRhdGUtcGVyc2lhbi1mb3Itc2ltcGxlLWRhdGUtcGlja2VyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14267
-
-

10 years 3 months ago [\#244836](#244836) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Jalali date (Persian) for simple date picker](/forum/33-customers/885428-jalali-date-persian-for-simple-date-picker#244836 "Hi.  I have a problem with simple date picker custom field (Address). My website language is Persian and i use jalali date in simple date picker, but when i save the address date don't save correctly and when i want to edit this address, date show incorrect.  Please see this pictures:  the problem is jalali date saved to database but this is mistake and jalali date should be convert to original date and then saved to database. and when i edit the address, original date should be convert to jalali and show to me.  Please help me. Thanks you.")*

Hi,

Try to add that code: Code:

function check(&amp;$field,&amp;$value,$oldvalue){ $value = JFactory::getDate()-&gt;format($value); return true; }

before the code: Code:

function showfield($viewObj, $namekey, $row) { if( isset( $row-&gt;$namekey)) { $date_format = !empty( $this-&gt;field_options['format']) ? $this-&gt;field_options['format'] : '%Y-%m-%d %H:%M:%S'; return hikashop_getDate( $row-&gt;$namekey, $date_format); } return ''; }

in the file administrator/components/com_hikashop/classes/field.php

The following user(s) said Thank You: [mahdi.manian](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy84ODU0MjgtamFsYWxpLWRhdGUtcGVyc2lhbi1mb3Itc2ltcGxlLWRhdGUtcGlja2VyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[mahdi.manian](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile")**
- [![mahdi.manian's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile") Topic Author
- [ Offline](/forum/user/38733-mahdi-manian)

Less More

- Posts: 2
- Thank you received: 0
-
-

10 years 3 months ago [\#244914](#244914) by [mahdi.manian](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile")  Replied by *[mahdi.manian](/forum/user/38733-mahdi-manian "View mahdi.manian's Profile")* on topic *[Jalali date (Persian) for simple date picker](/forum/33-customers/885428-jalali-date-persian-for-simple-date-picker#244914 "Hi.  I have a problem with simple date picker custom field (Address). My website language is Persian and i use jalali date in simple date picker, but when i save the address date don't save correctly and when i want to edit this address, date show incorrect.  Please see this pictures:  the problem is jalali date saved to database but this is mistake and jalali date should be convert to original date and then saved to database. and when i edit the address, original date should be convert to jalali and show to me.  Please help me. Thanks you.")*

Thanks but the problem is not resolved!

I added your code in that file, but i don't need call **check** function in here or another place? Where this function should be called?

I want convert my date to Gregorian date before storing in database. now Jalali date stored in database that this mistake and Gregorian date should be stored in database.

please help me. thank you.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy84ODU0MjgtamFsYWxpLWRhdGUtcGVyc2lhbi1mb3Itc2ltcGxlLWRhdGUtcGlja2VyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86290
- Thank you received: 14267
-
-

10 years 3 months ago [\#245873](#245873) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Jalali date (Persian) for simple date picker](/forum/33-customers/885428-jalali-date-persian-for-simple-date-picker#245873 "Hi.  I have a problem with simple date picker custom field (Address). My website language is Persian and i use jalali date in simple date picker, but when i save the address date don't save correctly and when i want to edit this address, date show incorrect.  Please see this pictures:  the problem is jalali date saved to database but this is mistake and jalali date should be convert to original date and then saved to database. and when i edit the address, original date should be convert to jalali and show to me.  Please help me. Thanks you.")*

Hi,

That's what this function is supposed to do.
The check function is called automatically by the system before storing the value of a custom field of that type so that it can verify the validity of the value.

Then try adding this code instead: Code:

function check(&amp;$field,&amp;$value,$oldvalue){ $date = explode('/',$value); $value = implode('/',$this-&gt;gregorian_to_jalali($date[0],$date[1],$date[2])); return true; } function div($a,$b) { return (int) ($a / $b); } function gregorian_to_jalali ($g_y, $g_m, $g_d,$str=false) { $g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29); $gy = $g_y-1600; $gm = $g_m-1; $gd = $g_d-1; $g_day_no = 365*$gy+$this-&gt;div($gy+3,4)-$this-&gt;div($gy+99,100)+$this-&gt;div($gy+399,400); for ($i=0; $i &lt; $gm; ++$i) $g_day_no += $g_days_in_month[$i]; if ($gm&gt;1 &amp;&amp; (($gy%4==0 &amp;&amp; $gy%100!=0) &#124;&#124; ($gy%400==0))) /* leap and after Feb */ $g_day_no++; $g_day_no += $gd; $j_day_no = $g_day_no-79; $j_np = $this-&gt;div($j_day_no, 12053); /* 12053 = 365*33 + 32/4 */ $j_day_no = $j_day_no % 12053; $jy = 979+33*$j_np+4*$this-&gt;div($j_day_no,1461); /* 1461 = 365*4 + 4/4 */ $j_day_no %= 1461; if ($j_day_no &gt;= 366) { $jy += $this-&gt;div($j_day_no-1, 365); $j_day_no = ($j_day_no-1)%365; } for ($i = 0; $i &lt; 11 &amp;&amp; $j_day_no &gt;= $j_days_in_month[$i]; ++$i) $j_day_no -= $j_days_in_month[$i]; $jm = $i+1; $jd = $j_day_no+1; if($str) return $jy.'/'.$jm.'/'.$jd ; return array($jy, $jm, $jd); }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMzLWN1c3RvbWVycy84ODU0MjgtamFsYWxpLWRhdGUtcGVyc2lhbi1mb3Itc2ltcGxlLWRhdGUtcGlja2VyP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop- Install &amp; Update- Product &amp; Category Display- Content Creation- Sales and Orders- - Orders management- - Reports &amp; Statistics- Customers- Checkout- Payment Methods- Shipping Methods- Import &amp; Export (CSV, XLS…)- Specific Features- - Affilation- - Taxes- - Wishlist- - Vote- - Carousel &amp; Slider- - Mass Actions- - Filters &amp; Search- - Discount &amp; Coupon- - Feature Request- Integrations- Showcase- General Talk about HikaShop- Development- - HikaShop 3.0 Beta- Translation- Commercial Jobs HikaShop Components- HikaMarket- - Market: Feature requests- - Market: How to?- - Market: Bug Report- HikaSerial- - General talk about HikaSerial- - Serial: Bug Report- - Serial: How to?- - Support en Français de HikaSerial (French Support)- - HikaSubscription- HikaAuction- - Auction: Feature requests- - Auction: How to?- - Auction: Bug report Hikashop around the world- Support en Français (French Support)- Russian- - FAQ. Курс выживания с Hikashop. Частые вопросы и о- - Расширения Hikashop- - Наши сайты на Hikashop- 日本語版サポート(Japanese Support)- Thai- German Archives- Bug Report- How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.149 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
