I am trying to import a date into a date picker so I can use the range feature to filter the data.
Currently I am using the code below to convert the data into what I assume is the right format.
[date( "Y-m-d H:i:s", strtotime( str_replace("/",".",{approvaldate[1]}) ) )]
Using the preview in the editor, I am seeing my original date:
Example:
"<approvaldate>9/2/2021</approvaldate>"
Converts to
"2021-02-09 00:00:00"
I was using this solution.
https://stackoverflow.com/questions/64254986/wp-all-import-pro-function-to-change-date-and-time-format-from-imported-csv
But in the backend, the date picker field shows empty when I edit the node.
Any help is appreciated. Thank you!
My View: hidden link
Hi,
Thank you for contacting us and I'd be happy to assist.
The Toolset date type field, stores the date/time value in the UNIX timestamp format, and while importing the data in it, the same format should be used.
This means that in your code, you'll replace the format string "Y-m-d H:i:s" with "U":
( ref: hidden link )
[date( "U", strtotime( str_replace("/",".",{approvaldate[1]}) ) )]
I hope this helps and let me know if you need any further assistance around this.
regards,
Waqar
Hello Waqar,
Thank you for the assistance. That didnt seem to do the trick though but I realized I needed to remove the string replace to get the UNIX timestamps right.
[date( "U", strtotime( {approvaldate[1]} ) )]
Now when I run the import, I get the following (example)
Input Date:
9/24/2021
Unix conversion:
1632441600
That is correct but in the date picker, it is displaying as follows.
July 19, 1600
(Attached is a screenshot).
Do I need a separate field for the displaying the date in the view that isnt translated?
Thanks for writing back and sorry about missing the "str_replace" part.
To troubleshoot this, I'll need to see how the data of these imported custom fields are showing in the back end.
Can you please share temporary admin login details, along with the example of a few imported posts with this date field?
Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.
Thank you for sharing the admin access.
I've checked the edit screen of all 34 "Transparency Reports" posts on the website and they all are showing the "Approval Date" field value correctly.
I also didn't see any abnormality in the date picker either and it follows the default behavior of starting from the current date.
This suggests that the import process for these date-type fields was completed successfully. I'll recommend checking the edit screen of all those posts again, after clearing the browser's cache.
If you still see something out of place, please share the exact steps to see it.
Hey Waqar,
The date shows but it doesnt work with the date picker filter on my view:
hidden link
Also, when you click the date picker on the edit page, it doesnt show the same date on the calendar as the one shown.
My main goal is to get the date range picker working though.
> The date shows but it doesnt work with the date picker filter on my view:
> My main goal is to get the date range picker working though.
- I'm not sure what settings you used to add the date range filter fields in the view "Transparency Report" earlier.
But, I've removed the existing date field filter for the "Approval Date" field and added a new one and it seems to be working now.
( screenshot of the settings I used: hidden link )
> Also, when you click the date picker on the edit page, it doesn't show the same date on the calendar as the one shown.
- As I mentioned in my previous reply, that is the normal/default behavior. When you'll open the date picker in the post edit screen to select a new date, it starts from today's date and not from the existing/selected date in the field.
( example screenshot from my test website: hidden link )
Great, it looks like I was setting up the date range selector incorrectly.
I was setting the Filter Comparison to DATE or DATETIME and it looks like I needed to set it up as a NUMBER instead. Weird to me but it works! Thank you.