CSV Import

teoyh

Member
I have this date element
upload_2021-2-4_15-44-45.png
Which i set the store Date As local time

In my listcsv import script ;

I had written this code to convert the string date to the date value

$ogiftdate = $formModel->formData['stml_gift_recipient___giftdate']; //DATE
date_default_timezone_set( 'Asia/Singapore');
$giftdate = date('Y-m-d',strtotime("$ogiftdate"));

I did a dump of the $giftdate and confirm it is correct as my csv file but the moment it get imported the day is always 1 day less the actual date in my csv file example 2021-02-03 in my csv file but actual value store is 2021-02-02

Can someone help me with this , thank you in advance
 
Hello from Singapore!

"2021-02-03" is really "2021-02-03 00:00:00". I suspect that, since this is GMT +8, it's stored in the database in UTC (= GMT) as "2021-02-02 16:00:00". Can you check?
In list, details, etc it should then be displayed depending on your (Joomla) site timezone setting. So, if that's set to Singapore, you should see the correct "2021-02-03" across the site.
 
Date with timezone is tricky. I don't know what the import is doing exactly with local/UTC times.

But if "the day is always 1 day less the actual date" I would add this day in the code.
 
I have define in my php.ini set date.timezone =Asia/Singapore

In mysql when i do a select select current_Date from table limit 1 it return current date which is also correct, i had localize everything in my environment

If no other choice i will just add 1 day loh
 
Ok i realise after i do the conversation i need to write back the converted value to the field in the csv > $formModel->updateFormData('stml_gift_recipient___giftdate', $giftdate);

$ogiftdate = $formModel->formData['stml_gift_recipient___giftdate']; //DATE
$giftdate = date('Y-m-d',strtotime("$ogiftdate + 24 hours"));
$formModel->updateFormData('stml_gift_recipient___giftdate', $giftdate);

Now working thanks all
 
Good to hear you've got it working.

Just for the record:
I have define in my php.ini set date.timezone =Asia/Singapore
That's server time. What I was referring to is the timezone set in Joomla -> Global Configuration -> Server tab -> Location Settings -> Website Time Zone.

As @troester said, dates with timezone are (always) tricky considering server time, database storage, Joomla site setting, eventually user timezone, etc etc.

But, again, good you got it working ok anyway.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top