Skip Navigation

[Resolved] Formatting dates correct from imported data

This support ticket is created 6 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by Cam Macduff 6 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#573467

Tell us what you are trying to do? Import a large existing data set via WP Import All plugin.
There are 'date fields' in the data set, but they're formatted like this: 19500328
Or in plain english: 1950 March 28.

But when imported they show up in Toolset's fields as a completely different date.
The field I'm importing into is set as a 'date' field.

Is there any documentation that you are following? Yes, theirs in regard to importing data. But there's nothing on how to format a date.

Is there a similar example that we can see? hidden link

What is the link to your site? hidden link

#573521

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Types date custom field is a special kind of a field that uses timestamps to store the value. So - you need to convert your date string to Timestamp and store it to database.

So - basically you need to prepare a script that convert your date string to untix timestamp and save the timestamp value as associated field value.

More info:
hidden link
hidden link

#573605

Ok, gotacha.
So, if we leave it as a string, is their a way to format it so it's human readable?
We could change the field type from date to number? or.. something else?

#573609

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - you should create a custom field with field type = Date and if you want to import the date value, you need to convert your date string to timestamp.

So - if you are using Types date custom field - it will accept value as timestamp.

Unfortunately - you can not format the date string unless you build some custom shortcode and pass the date string to it and convert it to date object and return the formatted date.

#573933

I was thinking if we just made the field a number field and output it as is, then wrapped it with some php to transform it?
Like:

$datetime = "20130409163705";
$d = DateTime::createFromFormat("YmdHis", $datetime);
echo $d->format("d/m/Y H:i:s")

Can we do that inside of Toolset's editor window?

#573971

I see someone else has the exact same issue with Toolset here: https://toolset.com/forums/topic/csv-importer-imports-incorrect-values-of-custom-date-field-showing-year-1970/#post-573966

I've tried the suggested plugin as a solution to this issue from the post above, but WP All Import doesn't seem to change them.

#574005

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - as you suggested here the workaround. That might work but the code you shared should be warped with custom shortcode.
=> https://toolset.com/forums/topic/formatting-dates-correct-from-imported-data/#post-573933

And to build custom shortcode will be an alternative I already shared that solution with you in my previous reply:
=> https://toolset.com/forums/topic/formatting-dates-correct-from-imported-data/#post-573609

Now, the old ticket link you shared is really old and we can not rely on that. I suggest better to import your date field as string and then build custom shortcode and the custom shortcode should return you formatted date as per your need.

#574712

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please close this ticket as well 🙂

#574716

Happy ending

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.