Обсуждение: Date format

Поиск
Список
Период
Сортировка

Date format

От
Dylan Fogarty-MacDonald
Дата:
Hi,

I have two fields of column type 'date' from which I want to output a
formatted date (with PHP).

I understand that MySQL  would use DATE_FORMAT and appropriate %M, %D
commands.
I am having trouble finding the equivalent PostgresQL commands. I am
using PG 7.3.4.

I have found the template patterns for the conversions. I want it to be
in this format:

Day, DD Month YYYY

I do not know the function to format this so.

if to_date() converts a string to date, what converts/formats date to
string?

Thankyou very much.

-Dylan Fogarty-MacDonald
dylan.fm@gmail.com

Re: Date format

От
Michael Glaesemann
Дата:
On Jul 31, 2006, at 14:23 , Dylan Fogarty-MacDonald wrote:

> I am using PG 7.3.4.

I strongly recommend upgrading, if not to the latest 8.1.4, then to
the most recent release of 7.3.15. These include patches to security
flaws and data-loss-incurring bugs. 8.1.4 will most likely perform
much better for you as well.

> if to_date() converts a string to date, what converts/formats date
> to string?

I think you'll want to look at TO_CHAR:

http://www.postgresql.org/docs/current/interactive/functions-
formatting.html

I've found it useful to use EXTRACT(EPOCH FROM your_timestamp) to
pass the timestamp to PHP, and then use the PHP timestamp formating
functions.

http://www.postgresql.org/docs/current/interactive/functions-
datetime.html#FUNCTIONS-DATETIME-EXTRACT

Hope this helps.

Michael Glaesemann
grzm seespotcode net




Re: Date format

От
Michael Glaesemann
Дата:
On Jul 31, 2006, at 14:38 , Michael Glaesemann wrote:

> I strongly recommend upgrading, if not to the latest 8.1.4, then to
> the most recent release of 7.3.15.

Sorry. That should read: ... most recent release of 7.3, which is
7.3.15.

Michael Glaesemann
grzm seespotcode net




Re: Date format

От
"Phillip Smith"
Дата:
If you are using PHP, then as Michael mentioned, you can either use the
Postgres to_char function to return the date formatted in the SQL query, or
use the PHP date() function to format it. Eg:

SQL:
    to_char('01-07-2005', Day, DD Month YYYY') AS "Date"
Returns:
    Friday   , 01 July       2005

PHP:
    date('L, d F Y', mktime(0, 0, 0, 07, 01, 2005))
Returns:
    Friday, 01 July 2005

Note the extra spaces in the SQL version. They are padded out to the maximum
possible length of that string - ie, Friday is padded out to the number of
characters in 'Wednesday' - That's my understanding anyway; Someone care to
correct me?

Cheers,
-p

-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org] On Behalf Of Dylan
Fogarty-MacDonald
Sent: Monday, 31 July 2006 15:23
To: pgsql-novice@postgresql.org
Subject: [NOVICE] Date format

Hi,

I have two fields of column type 'date' from which I want to output a
formatted date (with PHP).

I understand that MySQL  would use DATE_FORMAT and appropriate %M, %D
commands.
I am having trouble finding the equivalent PostgresQL commands. I am
using PG 7.3.4.

I have found the template patterns for the conversions. I want it to be
in this format:

Day, DD Month YYYY

I do not know the function to format this so.

if to_date() converts a string to date, what converts/formats date to
string?

Thankyou very much.

-Dylan Fogarty-MacDonald
dylan.fm@gmail.com

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org


*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee.  If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

Re: Date format

От
Dylan Fogarty-MacDonald
Дата:
Thankyou very much.

I tried with PHP date() but I had a few problems.

I ended up using the SQL, and it works as this in the query:

          to_char(project_enddate, 'Day, DD Month YYYY') AS enddate,
to_char(project_startdate, 'Day, DD Month YYYY') AS startdate

In regards to upgrading to the latest Pgsql - I would love that but I am
not running the server, I can suggest the upgrade but I do not know if
that will occur.

Luckily I am setting up a couple of servers in my spare time at work, so
eventually I can use them.

Thanks again,
-Dylan Fogarty-MacDonald

Phillip Smith wrote:

>If you are using PHP, then as Michael mentioned, you can either use the
>Postgres to_char function to return the date formatted in the SQL query, or
>use the PHP date() function to format it. Eg:
>
>SQL:
>    to_char('01-07-2005', Day, DD Month YYYY') AS "Date"
>Returns:
>    Friday   , 01 July       2005
>
>PHP:
>    date('L, d F Y', mktime(0, 0, 0, 07, 01, 2005))
>Returns:
>    Friday, 01 July 2005
>
>Note the extra spaces in the SQL version. They are padded out to the maximum
>possible length of that string - ie, Friday is padded out to the number of
>characters in 'Wednesday' - That's my understanding anyway; Someone care to
>correct me?
>
>Cheers,
>-p
>
>-----Original Message-----
>From: pgsql-novice-owner@postgresql.org
>[mailto:pgsql-novice-owner@postgresql.org] On Behalf Of Dylan
>Fogarty-MacDonald
>Sent: Monday, 31 July 2006 15:23
>To: pgsql-novice@postgresql.org
>Subject: [NOVICE] Date format
>
>Hi,
>
>I have two fields of column type 'date' from which I want to output a
>formatted date (with PHP).
>
>I understand that MySQL  would use DATE_FORMAT and appropriate %M, %D
>commands.
>I am having trouble finding the equivalent PostgresQL commands. I am
>using PG 7.3.4.
>
>I have found the template patterns for the conversions. I want it to be
>in this format:
>
>Day, DD Month YYYY
>
>I do not know the function to format this so.
>
>if to_date() converts a string to date, what converts/formats date to
>string?
>
>Thankyou very much.
>
>-Dylan Fogarty-MacDonald
>dylan.fm@gmail.com
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Have you searched our list archives?
>
>               http://archives.postgresql.org
>
>
>*******************Confidentiality and Privilege Notice*******************
>
>The material contained in this message is privileged and confidential to
>the addressee.  If you are not the addressee indicated in this message or
>responsible for delivery of the message to such person, you may not copy
>or deliver this message to anyone, and you should destroy it and kindly
>notify the sender by reply email.
>
>Information in this message that does not relate to the official business
>of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
>Weatherbeeta, its employees, contractors or associates shall not be liable
>for direct, indirect or consequential loss arising from transmission of this
>message or any attachments
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: don't forget to increase your free space map settings
>
>
>