Unix Technical Forum

Date Format Question

This is a discussion on Date Format Question within the pgsql Novice forums, part of the PostgreSQL category; --> Hi I do receive a date from a text box with this format: dd/mm/yyyy And i am inserting into ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 09:21 PM
=?iso-8859-1?q?=C2ngelo=20Marcos=20Rigo?=
 
Posts: n/a
Default Date Format Question

Hi

I do receive a date from a text box with this format:
dd/mm/yyyy

And i am inserting into Postgresql Database usign
(eg.):
INSERT INTO Mycalendar (Date) VALUES
(to_date('31/12/2005','mm/dd/yyyy')).

But for the "day" values above 10 (wich have not a
zero on his front) the month gets in the day place in
the database so :
31/12/2005 wich was suposed to be stored in this
format 2005-31-12

Is being stored in this format : 2005-12-31

How can i store the date in the right
format2005-31-12) ?

Thank´s in advance



Ângelo Marcos Rigo
AMR Informática
(51) 3348 0870
Rua Pe. Alois Kades 400/210
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo@yahoo.com.br










__________________________________________________ _____
Yahoo! doce lar. Faça do Yahoo! sua homepage.
http://br.yahoo.com/homepageset.html


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 09:21 PM
Frank Bax
 
Posts: n/a
Default Re: Date Format Question

At 01:33 PM 12/5/05, Ângelo Marcos Rigo wrote:
>I do receive a date from a text box with this format:
>dd/mm/yyyy
>
>And i am inserting into Postgresql Database usign
>(eg.):
>INSERT INTO Mycalendar (Date) VALUES
>(to_date('31/12/2005','mm/dd/yyyy')).
>
>But for the "day" values above 10 (wich have not a
>zero on his front) the month gets in the day place in
>the database so :
>31/12/2005 wich was suposed to be stored in this
>format 2005-31-12



That's weird, because on my system to_date('31/12/2005','mm/dd/yyyy')
produces 2007-07-14! Perhaps you meant to_date('31/12/2005','dd/mm/yyyy')?


>Is being stored in this format : 2005-12-31



No it's not - that's just how you "see" it with a default select of date
column.


>How can i store the date in the right format2005-31-12) ?



You cannot - but to_char(date,'dd/mm/yyyy') might be what you are really
looking for.


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 09:21 PM
Tom Lane
 
Posts: n/a
Default Re: Date Format Question

Frank Bax <fbax@sympatico.ca> writes:
> That's weird, because on my system to_date('31/12/2005','mm/dd/yyyy')
> produces 2007-07-14!


Yeah, to_date()'s lack of error checking is disgraceful. For most
purposes, it'd be better to read this data using the normal date
input converter with DATESTYLE set to DMY (or MDY if that's what you
really wanted).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-17-2008, 09:21 PM
Frank Bax
 
Posts: n/a
Default Re: Date Format Question

At 02:42 PM 12/5/05, Tom Lane wrote:

>Frank Bax <fbax@sympatico.ca> writes:
> > That's weird, because on my system to_date('31/12/2005','mm/dd/yyyy')
> > produces 2007-07-14!

>
>Yeah, to_date()'s lack of error checking is disgraceful. For most
>purposes, it'd be better to read this data using the normal date
>input converter with DATESTYLE set to DMY (or MDY if that's what you
>really wanted).



I didn't mean the 2007-7-14 was weird result. It was weird that OP's
results could not have come from the command he claimed to have
entered. OP claimed that to_date('31/12/2005','mm/dd/yyyy') produced
12/31/2005; but that's not possible.


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

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:31 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com