---
title: "MySQL和PostgreSQL日期格式化"
author: "wkj1209"
date: "2012-02-20T18:07:31Z"
tags: []
categories: ["Web前端"]
slug: "mysql-postgresql"
draft: false
lastmod: "2012-02-20T18:07:30Z"
id: 1413818
url: "https://wangkejun.iteye.com/blog/1413818"
---

MySQL：

select DATE\_FORMAT(CURRENT\_TIMESTAMP,'%Y-%m-%d %H:%i:%s') AS col1,CURRENT\_TIMESTAMP as col2

```

```

 PostgreSQL：

select to\_char(CURRENT\_TIMESTAMP,'yyyy-mm-dd hh24:mi:ss') AS col1,CURRENT\_TIMESTAMP as col2

```

```

 

 例：

```
select to_char(CURRENT_TIMESTAMP,'yyyy-MM') AS col1,CURRENT_TIMESTAMP as col2
```