Skip Navigation

[Resolved] convert text format of date fieldto unix timestamp

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by Luo Yang 6 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#908024

Hello, scraped data resource form external, and stored into database, but the custom date field was text format, it can be displayed in front-end, but I have to convert them to Unix timestamp, otherwise, that field cannot be filtered by View. I don't know how to convert them, but I guess that should be two ways

1. add a piece of code to convert that text field to timestamp in database

2. add code to View for converting them to timestamp .

🙂

Can you help with this? Thank you !

#908100

Hello,

There isn't such a built-in feature within Views plugin or other Toolset plugin, Views plugin is for rendering the content, it isn't for change the data.

It needs custom codes, for example you can run SQL query to change the date from string to timestamp, see similar thread here:
https://stackoverflow.com/questions/8587177/string-to-timestamp-in-mysql

And you would backup your database first before run those SQL query.

#908675

可以要求帮忙吗?我试了半天实在是不会啊,不可以的话 我也完全理解。谢谢~~~

#908786

你可以提供你的网站数据库备份文件吗?我需要在本机上进行测试

#909168

我已经下载该文件,如果有什么发现,我会更新此贴。

#909171

你可以使用MYSQL 工具例如PHPMYADMIN,在你的网站数据库内运行如下SQL语句:

UPDATE wp_postmeta
SET meta_value = (SELECT UNIX_TIMESTAMP(STR_TO_DATE(`meta_value`,'%b-%d-%Y')))
WHERE meta_key='wpcf-available-from'

上面的例子就可以将wpcf-available-from这个custom field 数据更新为timestamp.