PDA

View Full Version : Date Format Problem (Bug)?



errodr
30 Jun 2009, 6:48 AM
Hello,

I have a grid where I have a date called start, defined as:


{name: 'start', type:'date', dateFormat:'M j Y h:i:s:000A'}Out of the database the datetime fields (SQL Server 2008) look like this:


1. Apr 2 2007 08:00:00:000AM
2. Mar 10 2008 08:00:00:000AMIn my grid definition I use a renderer:formatDate for this field. The function looks like this:


function formatDate(value){
return value ? value.dateFormat('m-d-Y') : '';
};I thought I was using the proper formatting string, but only the string with the two-digit day is being formatted correctly. The second date string returns "03-10-2008 " while the first date string returns empty. If, however I change the format string like so (adding extra space after "M"):


{name: 'start', type:'date', dateFormat:'M j Y h:i:s:000A'}The first string is formatted correctly while the second string is not.

Where am I going wrong?

Thanks...

errodr
30 Jun 2009, 10:08 AM
Anybody? Anything?

tryanDLS
30 Jun 2009, 10:56 AM
Please don't bump your thread hours after you post. The community will respond when they have a chance to read your post and have an answer.

mystix
30 Jun 2009, 11:18 AM
from the docs for Date.parseDate (http://extjs.com/docs/?class=Date&member=parseDate):
(emphasis added)


...
Keep in mind that the input date string must precisely match the specified format string or the parse operation will fail.
...

that single space counts a valid character to match against, so of course the parsing will fail for either of your date strings if it's present / missing.

normal databases don't pad date strings with arbitrary spaces -- are you sure you're not padding the dates in your SQL code somewhere?

errodr
30 Jun 2009, 11:34 AM
Please don't bump your thread hours after you post. The community will respond when they have a chance to read your post and have an answer.

Thanks!

errodr
30 Jun 2009, 11:42 AM
from the docs for Date.parseDate (http://extjs.com/docs/?class=Date&member=parseDate):
(emphasis added)

that single space counts a valid character to match against, so of course the parsing will fail for either of your date strings if it's present / missing.

normal databases don't pad date strings with arbitrary spaces -- are you sure you're not padding the dates in your SQL code somewhere?

Thanks. I read the documentation.

SQL:


SELECT start_date FROM table;

As you can see, no padding going on. I'll just write my own parser...

mystix
30 Jun 2009, 6:45 PM
Thanks. I read the documentation.

apparently not the SQL Server 2008 documentation:
http://www.sql-server-performance.com/articles/dev/datetime_2008_p1.aspx


in your ColumnModel definition, use the following renderer:


renderer: Ext.util.Format.dateRenderer('m-d-Y')


in your SQL code, cast start_date to type datetime2 (i use PostgreSQL -- you're on your own here), which returns date strings in either of the following 2 formats:


2007-10-28 22:11:20
2007-10-28 22:11:19.7030000

(notice there's no padding going on there)

and depending on which of the above 2 date strings are returned by your server, in your Record definition, use either of the following definitions:


{name: 'start', type: 'date', dateFormat: 'Y-m-d H:i:s'}

or


{name: 'start', type: 'date', dateFormat: 'Y-m-d H:i:s.u'}


note:
in the next minor 2.x release / current 3.0 release, you could simply use the following Record definition:


{name: 'start', type: 'date', dateFormat: 'c'}

errodr
30 Jun 2009, 7:06 PM
apparently not the SQL Server 2008 documentation:
http://www.sql-server-performance.com/articles/dev/datetime_2008_p1.aspx


in your ColumnModel definition, use the following renderer:


renderer: Ext.util.Format.dateRenderer('m-d-Y')


in your SQL code, cast start_date to type datetime2 (i use PostgreSQL -- you're on your own here), which returns date strings in either of the following 2 formats:


2007-10-28 22:11:20
2007-10-28 22:11:19.7030000

(notice there's no padding going on there)

and depending on which of the above 2 date strings are returned by your server, in your Record definition, use either of the following definitions:


{name: 'start', type: 'date', dateFormat: 'Y-m-d H:i:s'}

or


{name: 'start', type: 'date', dateFormat: 'Y-m-d H:i:s.u'}


note:
in the next minor 2.x release / current 3.0 release, you could simply use the following Record definition:


{name: 'start', type: 'date', dateFormat: 'c'}


Wow, I'm glad you know what I have and have not read. I READ the pertinent documentation for SQL Server AND extJS. I realize that I can easily convert or cast the datetime to a different more suitable datatype. I am unable to do that for certain reasons, I have to work with exactly what is spit out of the database.

I have fixed the problem by writing my own parser. Thanks anyway...