Skip Navigation

[Resolved] Formatting dates correctly on import

This support ticket is created 6 years, 7 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 6 replies, has 3 voices.

Last updated by filipV-3 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#573968

Tell us what you are trying to do?
Importing CSV into a lot of custom fields. Date fields included. But the dates are formatted: 19500223. Not Unix time stamps.
This seems to be a common problem for many WordPress users importing data.

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.

I've included a link below to my site with an example post I've imported data into. I've create a duplicate field of my date field that's just a text field so you can see what the is originally.
The top field is labelled "Rego Date" and that's just displaying the raw data imported as text.
The next field is labelled "Registration Date" and that's a proper datestamp field in Toolset and as you can see it's displaying it as the wrong date. It should be 1950 March 28, but instead it says Aug 14 1970.

Is there any documentation that you are following?
No.

Is there a similar example that we can see?
See above.

What is the link to your site? hidden link

#574053

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I see you open a new ticket for same question. We can continue with your old ticket if you do not have any issue and the forum URL you shared is really old.

As I suggested in your old ticket - you need to build a custom shortcode that will accept your date as string (as stored in your database now) and you should manipulate this date string to format your date.

If you need help with that, I need temporary access details with problem URL where you want to display date and in which format and which field I should use to get the current date field.

#574411

Minesh
Supporter

Languages: English (English )

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

Thanks for sharing access details but unfortunately wp-admin access details not working at this end. Could you please check once and resend access details.

Also - is this the link where you would like to display date field? If yes: which fields I need to work on?

I have set the next reply to private which means only you and I have access to it.

#574501

Minesh
Supporter

Languages: English (English )

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

Well - I can see that the date is stored as string in format 19540323 but I would like to know in which format you would like to display the "rego date" and "apc rego date"?

#574541

Minesh
Supporter

Languages: English (English )

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

Could you please check now. I've added the following code to your current theme's functions.php file:

add_shortcode('show_date_with_format', 'func_show_date_with_format');
function func_show_date_with_format($atts) {
global $post;

    $date_string = get_post_meta($post->ID,'wpcf-'.$atts['field'], true);
    return date($atts['format'], strtotime($date_string));

}

Now, you can call above shortcode as:

[show_date_with_format field="rego-date" format="F j, Y"]
[show_date_with_format field="apc-rego-date" format="F j, Y"]

Where:
- field = your field name
- format = your required format to display the date

You are free to change the date format as required. 🙂

I can see its working now:
=> hidden link

Also, I see you have still your old ticket open - please mark resolve this as well as old ticket 🙂
=> https://toolset.com/forums/topic/formatting-dates-correct-from-imported-data/

#574708

Thanks Minesh, much appreciated. I'll update the other layouts with your code.
Much appreciated!

#582018

hi! I have the same issue and tried Minesh' solution; added the php code, but than: where actually goes the shortcode??
I use CSV importer (can't add the shortcodes there), i have the post fields 'date' ready (don't see where i can add the shortcodes there) and i see the results in the admin order pages where i also can't add that shortcode...?
Thanks a lot!

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