Date Format Problem

Hi,

I am generating a text file with the data from the documents (Web based application so agent is running on the server). The data is having Two date fields. the date format should be “dd.mm.yyyy” for both dates where as the format stored in the field is “dd/mm/yyyy” format, in agent i am using Replace(doc.StartDate(0),“/”,“.”) to show the format as “dd.mm.yyyy”

The above code displaying the date format properly in development Server (which is on windows platform). when i migrated the change to production Server (which is AIX 5.3 platform) the format showed is “dd.mm.yy” (i.e 9.10.09 or 24.3.09 truncating the zero if the value is less than 10 and year format is also wrong) format.

Any help would be greatly appreciated.

Subject: Date Format Problem

It sounds like the field StartDate is getting assigned a string value at some point, and that’s where your problem is coming from – the assignment of StartDate, not its later use. I believe StartDate is text because your call to Replace should give you a type mismatch error otherwise.

The solution to this is not to fix the assignment of StartDate to a correct string value. You must not store dates as strings.

Different servers and workstations have different date formatting rules, based on preferences or administrator settings, so one computer may not be able to interpret a date string created by a different computer (or may interpret it incorrectly, exchanging the month/year/day values).

If you store a date as a date/time value, there is no formatting stored in the field. The value is formatted by the end-user’s computer, using their date formatting preferences (or, you can override their preferences with custom settings in the field properties and view column properties infoboxes).

In the case where you need to generate a text file, obviously you have to store a string representing a date in the file. But it should not be a string before that point.

Please read about the Format function, which will let you control the conversion precisely and independent of local settings, without resorting to string functions.