Please help me.. problem in to_char

Please help me.. problem in to_char

am 21.07.2004 10:33:38 von izza76

Hi,
I want convert from mysql to postresql, previously
in mysql the code as below:

SELECT t2.id, t2.name, date_format(t1.created,\'%W %M %e, %Y - %r\')

In postresql no date_format function, we need to use to_char function
but it still work because still need to put ::date such as
SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');

How can i put ::date beside t1.created to get the output?
Any idea??

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Please help me.. problem in to_char

am 21.07.2004 14:15:57 von twanger

В Срд, 21.07.2004, в 10:33, azah azah пишет:
> Hi,
> I want convert from mysql to postresql, previously
> in mysql the code as below:
>
> SELECT t2.id, t2.name, date_format(t1.created,\'%W %M %e, %Y - %r\')
>
> In postresql no date_format function, we need to use to_char function
> but it still work because still need to put ::date such as
> SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');
>
> How can i put ::date beside t1.created to get the output?

Just do it:

to_char(t1.created::date, 'DD/MM/YYYY')

--
Markus Bertheau


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Re: Please help me.. problem in to_char

am 21.07.2004 14:35:06 von tedpet5

what kind of column is t1.created? It appears that it
is a text column and the format looks like a date. Is
this correct or is it a date? I need more information
about your table structure.

What about:

SELECT t2.id, t2.name, to_char(cast (t1.created as
date),'DD/MM/YYYY')

but the other '::' should work also.

extremedb=> SELECT to_char(cast ('12/4/2004' as
date),'DD/MM/YYYY');
to_char
------------
04/12/2004
(1 row)


extremedb=> SELECT
to_char('12/4/2004'::date,'DD/MM/YYYY');
to_char
------------
04/12/2004
(1 row)



I have a table with a timestamp in it called
createdate..


\d clientinfo
Table "public.clientinfo"
Column | Type |
Modifiers
-----------------+--------------------------+-----
acode | text |
not null
createdate | timestamp with time zone | default
now()


extremedb=> SELECT to_char(cast (clientinfo.createdate
as date),'DD/MM/YYYY') from clientinfo;
to_char
------------
14/07/2004
14/07/2004
14/07/2004



Ted

--- azah azah wrote:
> Hi,
> I want convert from mysql to postresql, previously
> in mysql the code as below:
>
> SELECT t2.id, t2.name, date_format(t1.created,\'%W
> %M %e, %Y - %r\')
>
> In postresql no date_format function, we need to use
> to_char function
> but it still work because still need to put ::date
> such as
> SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');
>
> How can i put ::date beside t1.created to get the
> output?
> Any idea??
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
> majordomo@postgresql.org
>



__________________________________
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Re: Please help me.. problem in to_char

am 22.07.2004 04:43:35 von izza76

Why still not working???
I have try all the suggestions, still error like below:
ERROR: cannot cast type character varying to date
I'm using latest version of postresql.

On Wed, 21 Jul 2004 05:35:06 -0700 (PDT), Theodore Petrosky
wrote:
>
> what kind of column is t1.created? It appears that it
> is a text column and the format looks like a date. Is
> this correct or is it a date? I need more information
> about your table structure.
>
> What about:
>
> SELECT t2.id, t2.name, to_char(cast (t1.created as
> date),'DD/MM/YYYY')
>
> but the other '::' should work also.
>
> extremedb=> SELECT to_char(cast ('12/4/2004' as
> date),'DD/MM/YYYY');
> to_char
> ------------
> 04/12/2004
> (1 row)
>
> extremedb=> SELECT
> to_char('12/4/2004'::date,'DD/MM/YYYY');
> to_char
> ------------
> 04/12/2004
> (1 row)
>
> I have a table with a timestamp in it called
> createdate..
>
> \d clientinfo
> Table "public.clientinfo"
> Column | Type |
> Modifiers
> -----------------+--------------------------+-----
> acode | text |
> not null
> createdate | timestamp with time zone | default
> now()
>
> extremedb=> SELECT to_char(cast (clientinfo.createdate
> as date),'DD/MM/YYYY') from clientinfo;
> to_char
> ------------
> 14/07/2004
> 14/07/2004
> 14/07/2004
>
> Ted
>
> --- azah azah wrote:
> > Hi,
> > I want convert from mysql to postresql, previously
> > in mysql the code as below:
> >
> > SELECT t2.id, t2.name, date_format(t1.created,\'%W
> > %M %e, %Y - %r\')
> >
> > In postresql no date_format function, we need to use
> > to_char function
> > but it still work because still need to put ::date
> > such as
> > SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');
> >
> > How can i put ::date beside t1.created to get the
> > output?
> > Any idea??
> >
> > ---------------------------(end of
> > broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to
> > majordomo@postgresql.org
> >
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - 50x more storage than other providers!
> http://promotions.yahoo.com/new_mail
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Re: Please help me.. problem in to_char

am 22.07.2004 04:59:08 von izza76

Thanks all, :)

It working now, i'm using code as below:
to_char(t1.created::date,'DD/MM/YYYY')

but other problem come out, error as below:
ERROR: relation "plugins" does not exist

what that's mean?? table plugins already exists..



On Thu, 22 Jul 2004 10:43:35 +0800, azah azah wrote:
> Why still not working???
> I have try all the suggestions, still error like below:
> ERROR: cannot cast type character varying to date
> I'm using latest version of postresql.
>
>
>
> On Wed, 21 Jul 2004 05:35:06 -0700 (PDT), Theodore Petrosky
> wrote:
> >
> > what kind of column is t1.created? It appears that it
> > is a text column and the format looks like a date. Is
> > this correct or is it a date? I need more information
> > about your table structure.
> >
> > What about:
> >
> > SELECT t2.id, t2.name, to_char(cast (t1.created as
> > date),'DD/MM/YYYY')
> >
> > but the other '::' should work also.
> >
> > extremedb=> SELECT to_char(cast ('12/4/2004' as
> > date),'DD/MM/YYYY');
> > to_char
> > ------------
> > 04/12/2004
> > (1 row)
> >
> > extremedb=> SELECT
> > to_char('12/4/2004'::date,'DD/MM/YYYY');
> > to_char
> > ------------
> > 04/12/2004
> > (1 row)
> >
> > I have a table with a timestamp in it called
> > createdate..
> >
> > \d clientinfo
> > Table "public.clientinfo"
> > Column | Type |
> > Modifiers
> > -----------------+--------------------------+-----
> > acode | text |
> > not null
> > createdate | timestamp with time zone | default
> > now()
> >
> > extremedb=> SELECT to_char(cast (clientinfo.createdate
> > as date),'DD/MM/YYYY') from clientinfo;
> > to_char
> > ------------
> > 14/07/2004
> > 14/07/2004
> > 14/07/2004
> >
> > Ted
> >
> > --- azah azah wrote:
> > > Hi,
> > > I want convert from mysql to postresql, previously
> > > in mysql the code as below:
> > >
> > > SELECT t2.id, t2.name, date_format(t1.created,\'%W
> > > %M %e, %Y - %r\')
> > >
> > > In postresql no date_format function, we need to use
> > > to_char function
> > > but it still work because still need to put ::date
> > > such as
> > > SELECT to_char('2005-03-27'::date,'DD/MM/YYYY');
> > >
> > > How can i put ::date beside t1.created to get the
> > > output?
> > > Any idea??
> > >
> > > ---------------------------(end of
> > > broadcast)---------------------------
> > > TIP 1: subscribe and unsubscribe commands go to
> > > majordomo@postgresql.org
> > >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Yahoo! Mail - 50x more storage than other providers!
> > http://promotions.yahoo.com/new_mail
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> >
>

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend