Skip Navigation

[Resolved] Migrate date field to other field format

This support ticket is created 5 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 14 replies, has 3 voices.

Last updated by Christian Cox 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1327291

We need to be able to select dates before 1583. I see conflicting response to this problem.
https://toolset.com/forums/topic/in-date-picker-select-years-before-1583/ that sys the issue will be solved in Types 2.3 and others that says it can't be done. How can we migrate the data from a date field into some other custom field format?

#1327293

Please provide all the relevant details here:
- What type of field will you convert to?
- What will be the new field slug?
- Do you have any Views that utilize this date field as a filter, or for sorting criteria?
- Are there any conditional HTML shortcodes that rely on this date field?
- Where can I find your data export files?

Thank you.

#1327351
Screen Shot 2019-08-29 at 10.44.43 AM.jpg
Screen Shot 2019-08-29 at 10.44.17 AM.jpg

OK
- What type of field will you convert to?
SINGLE LINE TEXT FIELD FOR POSTE TYPE DEFINITIONS
hidden link

- What will be the new field slug?
EVENEMENT-DATE-2

- Do you have any Views that utilize this date field as a filter, or for sorting criteria?
DEFINITIONS

- Are there any conditional HTML shortcodes that rely on this date field?
NOT THAT RELY ON THE DATE FILED BUT THE DATE FIELD HAS A CONDITIONAL DISPLAY
Conditional display
Definitions Categories = Evenement

- Where can I find your data export files?
HAVEN'T EXPORTED ANYTHING

#1327381

May I log into wp-admin and see how the Definitions View is configured? Please provide login credentials in the private reply fields here.

#1327395

- Do you have any Views that utilize this date field as a filter, or for sorting criteria?
DEFINITIONS
I see a View called "Definitions lies a un Mot", but it is not filtered or sorted by the custom date field. I see another View called "Definitions Mots", but it is not filtered or sorted by the date field. Perhaps there was a miscommunication? If any Views are sorted or filtered by the event date custom field, we need to consider that before the data migration.

#1327439

Sorry I misunderstood. NO VIEW ARE FILTERED OR SORTED BY the date field.

#1327475

Okay thank you. Now we need to discuss date formats.
1. What format do you want to use to store dates in the database?
2. What format do you want to use to display the dates on the front-end of the site?

Let me explain some options. If you do not plan to use these dates for sorting, comparison, or filtering, then storing the dates as dd/mm/yyyy or some other readable format is fine. However, if you plan to use dates for sorting, comparison, or filtering, then you must use a different format, like Unix timestamp. Toolset's date fields use this format. For example, right now, the Unix timestamp is 1567107876. A tool like this can help you convert dates to timestamps: https://www.epochconverter.com/

This format allows easy sorting and comparison of dates, but it is not easily readable. To display that timestamp in a readable date format, you can use a custom shortcode:

add_shortcode( 'ts-format-date-l10n', 'ts_format_date_l10n_func');
function ts_format_date_l10n_func( $atts, $content ) {
  $a = shortcode_atts( array(
      'format' => '%c',
      'timestamp' => time()
  ), $atts );

  return strftime( $a['format'], $a['timestamp'] );
}

You can use that shortcode with a Unix timestamp like this:

[ts-format-date-intl format="%d %B, %Y" timestamp="[types field='evenement-date-2' output='raw'][/types]"]

The format %d %B, %Y will be displayed as dd mm, yyyy
Additional format documentation is available here: https://www.php.net/manual/en/function.strftime.php

#1328827

We will not use these dates for sorting, filtering or comparison.

Just to recap.
1. We are talking about the custom field "date" for Definitions post type.
2. As we need BC dates we cannot continue to use the date picker field because it is limited to the Gregorian calendar and the dev. team doesn't advice to change the core code with another epoch number.
3. we are creating a new field - Single Line with the slug "EVENEMENT-DATE-2" that will be used to enter the date as we wish.
4. You are helping us to convert the existing date picker entries to a "single line" text as this will be the new format.
5. This field "EVENEMENT-DATE-2" will not be used for filtering, sorting or comparison.
6. The existing data can be converted as DD/MM/YYYY.

Am I following well?
Just a question why a new slug? why can't we converted the existing data and keep the same slug for the single line field?

Thanks

#1328981

Yes, your recap summary is accurate. We will continue with date format DD/MM/YYYY.

Just a question why a new slug? why can't we converted the existing data and keep the same slug for the single line field?
That would be a more complicated process. The existing field would have to be deleted before the migration can take place. That would delete all the existing values from the database. It's possible, but more complicated. For the purposes of this ticket, I would prefer to create a new field and move the values there first.

Please create the single-line text field "EVENEMENT-DATE-2" in the custom field editor. Then, create a SQL dump file from your database and post it somewhere like Dropbox or Drive, where I can download it. I will import that database locally and create the required scripts for migrating the custom field values. I'll make sure everything is working correctly locally before we update the production database.

#1329141
Screen Shot 2019-09-01 at 10.21.41 PM.jpg

Done - Created "Evenement Date 2"
Done - The db is on drive. Which email address do I use to share it with you?

Thank you.

#1329685

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Charles,

Christian is currently on vacation today.

However he will be back tomorrow to continue working on this ticket with you.

Thanks,
Shane

#1330555

Here we are:
hidden link

#1330825
Screen Shot 2019-09-03 at 2.46.58 PM.png

Maybe I'm misunderstanding but this database only has one entry for the original field - wpcf-evenement-date - in post #5059. Is there more date information in a different field?

#1330849

Really! Sorry I am not the one entering data, I was told by the client that this was an issue and that data had been entered. I should have checked before moving forward and "wasting" your time. My apologies. I'll let him know to update manually.

#1330887

No problem, it's better to be safe! Let me know if you need additional assistance here.