SQL PostgreSql + 日期格式 将 YYYY-MM-DD 转换为日、日、月、年

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4286817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:24:21  来源:igfitidea点击:

PostgreSql + Date Format Convert YYYY-MM-DD to Day, Date Month Year

postgresqlsqldate-comparison

提问by Rubyist

Suppose I am storing this format in my postgre database table. Now I have to compare this date with one of the texbox value contain date in different format.

假设我将此格式存储在我的 postgre 数据库表中。现在我必须将此日期与包含不同格式日期的 texbox 值之一进行比较。

Database Date Format :: YYYY-MM-DD For example :: 2010-11-26

Text-Field Date Format :: Day, Month Date, Year :: Fri, Nov 26, 10

Now I have tried to compare this value but no response Plz suggest.

现在我试图比较这个值,但没有回应 Plz 建议。

    Select * from table_name where user_id=('11') 
and to_char(effective_date, $$$$$$$$)=trim('Fri, Nov 26, 10');

Now Plz suggest which format should I use in place of $$$$$$$$ ???

现在请建议我应该使用哪种格式来代替 $$$$$$$$ ???

Thanks !!!

谢谢 !!!

回答by Frank Heikens

SELECT 
  * 
FROM 
  table_name 
WHERE 
  user_id=('11') 
AND 
  to_char(effective_date, 'Dy, Mon DD, YY') = trim('Fri, Nov 26, 10');

回答by a_horse_with_no_name

This should do it: to_char(effective_date, 'Dy, Mon DD, YY')

这应该这样做: to_char(effective_date, 'Dy, Mon DD, YY')

Btw: this is all documented in the manual: http://www.postgresql.org/docs/current/static/functions-formatting.html

顺便说一句:这都记录在手册中:http: //www.postgresql.org/docs/current/static/functions-formatting.html