简体   繁体   English

如何将文本数据类型的数据库字段中的 java 日期 toString 值格式化为 mysql 日期表示形式?

[英]How to format java date toString values in a database field with text data type into a mysql date representation?

Given i have a table in which a certain field has a text data type, lets say FieldValue coulmn given text as data type.鉴于我有一个表,其中某个字段具有文本数据类型,可以说 FieldValue coulmn 给定text作为数据类型。 I am saving a date object from java using the full format and saving this in the column like this:我正在使用完整格式从 java 保存日期 object 并将其保存在这样的列中:

Wed Jul 25 00:00:00 CST 2012

Now i want to make this a date type in my mysql query using str_to_date() function so that i can make a date to date comparison in my query.现在我想使用str_to_date() function 在我的 mysql 查询中将其设为日期类型,以便我可以在我的查询中进行日期到日期的比较。

Is this possible given the scenario above?考虑到上述情况,这可能吗?

try this, is working:试试这个,正在工作:

SET @var_time = 'Wed Jul 25 00:00:00 2012';

SELECT STR_TO_DATE(REPLACE(@var_time, 'CST ', ""),'%a %M %d %H:%i:%s %Y');

You can store result of above query in TIMESTAMP field in MySQL and do further operation on time and dates.您可以将上述查询的结果存储在 MySQL 中的TIMESTAMP字段中,并进一步对时间和日期进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM