Skip Navigation

[Resolved] Combine two Date-Fields in one textfield

This thread is resolved. Here is a description of the problem and solution.

Problem:
Combine two Date-Fields in one textfield

Solution:
you add a custom shortcode where you grab the types date field timestamp values and return the formatted date.

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/combine-two-date-fields-in-one-textfield/#post-1115670

Relevant Documentation:

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

Last updated by thomasB-2 6 years, 2 months ago.

Assisted by: Minesh.

Author
Posts
#1112967

I try to combine 2 Date fields (Startdate and Enddate) into a new field where both combined. I need it not only as view, but also as field, because it should be placed in an form (and the toolset Dates are only as linux Timestamp and could not used) creator as prefined Value.
F.e.
Startdate: 01.01.2018
Enddate: 02.01.2018
combined Field: 01.01.2018 - 02.01.2018

Was that possible?

#1113446

You have different options to combine data, it depends where you want to combine it, when, and where you want to output it.

I understand that you have 2 Fields (input) as Post Fields, they will show on the Backend of the Post Edit, and on the Toolset Form
When those fields are filled and the post saved or form submitted, you want to combine those 2 values and store that new value in another field (Simple text Field) and then output that somewhere.

You could create such "Simple Text Field".
To save data to the new Field, you would probably in your case use a PHP Snippet, hooked to either a Toolset Form API hook or a WordPress hook (generally save_post()). That snippet would get the value of the start and end date field, which as you recognized correctly is a Timestamp.
That can be converted to a date like you intend, and stored in a new field as a string to show on the front end later with the Field's ShortCode.
In a View, it can be used to query (however don't expect a date query for a string holding 2 humanly readable dates), and output as a ShortCode to see on the Front End.

However, maybe there is a much simpler approach, where you just display the information on the Front-end combining the values of the start and end date fields.
That is, if you do not need to store those dates but only show them in the format you outline.

Can you let me know the precise workflow that you intend to achieve?

Something like this I imagine should happen, but am not sure:
- Form or Post is saved with 2 Dates set in each a Toolset Date Field
- When this happens both dates are saved to a third single line field as a humanly readable date set
- That then is editable as a single string

If so, then it requires custom code.
The Hooks I elaborated are documented here:
https://toolset.com/documentation/programmer-reference/cred-api/
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

To work with Timestamp and convert it:
hidden link

To get Toolset fields values you can either use the native WordPress get_post_meta() or the Toolset native types_render_field().
To update fields you always use update_post_meta().
https://toolset.com/documentation/customizing-sites-using-php/functions/
https://developer.wordpress.org/reference/functions/get_post_meta/
https://codex.wordpress.org/Function_Reference/update_post_meta

Please let me know if you need more help with, here is as well a reference to such a Custom Code Snippet applied to a Toolset Form:
https://pastebin.com/2BTbVbcs (Update Post Title with any field)
https://pastebin.com/A2UMXVUJ (Update Post Title with Timestamp as base data and converted)

Please consult these rules and Contractors (In case you need extended help) of Toolset Support related to custom code as well:
https://toolset.com/toolset-support-policy/
https://toolset.com/contractors/

#1115144

Hi Beda,

we build an cpt called "events" and the datas for that was created in backend from editors.
In these cpt we have the fields Startdate and Enddate.

The customer could order such event on the frontend of the page, where the cpt was shown. The ordering process was managened not with Cred - Form, because the focus was not to create a new cpt post. We created the forms with formidablepro.

And now we have the problem to show the Start- and enddate in the mails generated with that form.
I could catch in formidable the cpt fields from Types, but because Types saves dates only as Unix-Timestamp i could not use it in the Mails.

So the idea was to place the Startdate and Enddate together in an Textfield (Startdate: 01.02.2018, Enddate 03.02.2018 as Textfield "01.02.2018 - 03.02.2018".
If that was possible i could add these field in the mail coming from formidable forms.

#1115567

Minesh
Supporter

Languages: English (English )

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

And now we have the problem to show the Start- and enddate in the mails generated with that form.
I could catch in formidable the cpt fields from Types, but because Types saves dates only as Unix-Timestamp i could not use it in the Mails.
==> Well - yes, Types stores custom date field value as timestamp. but when you use types shortcode to display the date, it will give you the formatted date.

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#date

So the idea was to place the Startdate and Enddate together in an Textfield (Startdate: 01.02.2018, Enddate 03.02.2018 as Textfield "01.02.2018 - 03.02.2018".
If that was possible i could add these field in the mail coming from formidable forms.
==> I would like to know from where you want to combine the date field? using Toolset form or formidable form? Could you please share problem URL?

#1115625

The Dates should be placed in Mail sending from Formidable.
For that it must be shown in Formidable with a call of the postmeta-Data of the wpcf value of the specific field.
These works perfectly for also the date-fields. But these shows only the Value of the timestamp.
Therefore we try to combine startdate / enddate in one field.
We could not made these in the form directly, because these doesn't handle the types shortcodes.

So the idea was to combine both fields in a new one when the post was created.

#1115670

Minesh
Supporter

Languages: English (English )

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

These works perfectly for also the date-fields. But these shows only the Value of the timestamp.
==> But what if you add a custom shortcode where you grab the types date field timestamp value and return the formatted date. Will this help?

OR
You just wanted to go for the solution of combining date fields? If Yes:
I would like to know to where and how you are saving the dates?

#1115694

In the cpt "Veranstaltung" if have the datefield "startdatum" and the datefield "enddatum". Both fields are filled while creating a new "Veranstaltung".
Both should be combined to a new field "datum" wich should be a textfield, so that we can display it in an other way then the linux timestamp value.

#1115714

My issue is resolved now. Thank you!

Test it now with the shortcodes - and it works. Great.

Tnx for quick and fast support.

Bye Thomas