将日期格式从varchar更改为yyyy-mm-dd [英] change date format to yyyy-mm-dd from varchar in postgres

查看:323
本文介绍了将日期格式从varchar更改为yyyy-mm-dd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SELECT
  to_char("date", 'YYYY/MM/DD') 
  "public".teacher_details.teacher_id,
  "public".teacher_details.first_name,
  "public"."TblFacultyMaster"."MastCode",
  "public"."TblFacultyMaster"."MastName",
  "public"."TblFacultyMaster"."DOB",
  "public".teacher_details.dob
FROM
  "public".teacher_details
INNER JOIN "public"."TblFacultyMaster" ON "public"."TblFacultyMaster".teacher_id = "public".teacher_details.teacher_id

我正在尝试将日期格式从dd / mm / yyyy到yyyy-mm-dd,类型为varchar,因为我的TblFacultyMaster表中有yyyy-mm-dd格式,而Teachers_deatil表
中有dd / mm / yyyy,我想匹配常见的DOB,但是格式两者的表都不同

I am trying to convert date format from dd/mm/yyyy to yyyy-mm-dd and the type is varchar , since I have yyyy-mm-dd in format in my TblFacultyMaster table and dd/mm/yyyy in my teachers_deatil table I want to match common DOB but the format is different in both table

请帮助

预先感谢

推荐答案

to_char 无法将字符串转换为字符串,尝试将日期与类型转换为varchar datecolumn 在这里,我想 date是您的那列,请尝试如下所示的

to_char can not convert string to string, try to typecast with date to the varchar datecolumn here i suppose to "date" is your that column, try like below :

SELECT
  to_char("date"::date, 'YYYY/MM/DD') as date, 
  "public".teacher_details.teacher_id,
  "public".teacher_details.first_name,
  "public"."TblFacultyMaster"."MastCode",
  "public"."TblFacultyMaster"."MastName",
  "public"."TblFacultyMaster"."DOB",
  "public".teacher_details.dob
FROM
  "public".teacher_details
INNER JOIN "public"."TblFacultyMaster" ON "public"."TblFacultyMaster".teacher_id = "public".teacher_details.teacher_id

这篇关于将日期格式从varchar更改为yyyy-mm-dd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆