Date Format Problem - I don't think there is an answer for it

Hello Everyone:

I have a problem with dates and I really don’t think there is an answer for it. I am passing this to the experts to see if there is a way to do it. There is a process in the application which produces a text file with part number and date. This file is then send by e-mail or flash memory to someone who runs an agent that matches the part number with part description and other details and also adds the date stamp. I had run into a problem and after a long time in debug mode I fund that some laptops out in the field have a different date format like if the date is September 11, 2008 some reports will come as 10/11/08 and others as 11/10/08. Based on the computer doing the final report this may be two different dates or the way I found it, it creates an error. I don’t think there is a way to find which date format was used to create the first log the one with the part number and date. If you have any ideas please let me know!!!

Thanks

Subject: Date Format Problem - I don’t think there is an answer for it

Of course the are many ways do deal with date format.The easiest on is to use functions such as @Year, @Month and @Day.

Whatever the format is, those functions will return the right values, so you can compare them.

Another way is to use Format(Cstr(Date) , “dd-mm-yy”) in LotusScript, where Date is your date value.

Cheers,

Fadi Kiwan

Subject: Date Format Problem - I don’t think there is an answer for it

Whenever I handle dates, I ALWAYS use the ANSI format YYYYMMDD, ALWAYS.

This will NEVER create any problems.

Subject: RE: Date Format Problem - I don’t think there is an answer for it

Oh yeah?

My machine is set up with typical North American settings (en-us – Canadian English settings cause too many problems with too many programs to bother with).This code in a button:

Sub Click(Source As Button)

Dim dateSource As String

Dim actualDate As Variant

dateSource = "20080215"

On Error Goto HandleError

actualDate = Cdat(dateSource)

Messagebox "Your date was " & actualDate

SafeExit:

Exit Sub

HandleError:

Messagebox "Could not convert datestring " + dateSource

Resume SafeExit

End Sub

Gives me this result:

You may be able to PARSE an ANSI date without failure, but don’t count on a safe conversion.

Subject: RE: Date Format Problem - I don’t think there is an answer for it

Over the 20+yrs of programming I have learnt to always write code to convert the date to ANSI format with the Format method using the YYYYMMDD parameter right at the workstation where the code runs.

The point I am trying to make is when writing date to a text file using the YYYYMMDD convention saves a lot of grief.

Subject: RE: Date Format Problem - I don’t think there is an answer for it

My point is that one needs to understand – no, make that “to internalize” – that what you are storing is not a date, but a string in a known format that you know how to parse into a date value. As I’ve just proven, ANSI date strings are not necessarily understood by ANY computer. Picking a standard (YYYMMDD in your case; I prefer yyyy-mm-dd) makes life easier since you can reuse your parsing code (and the hyphens make a string format checking guard clause easier to write), but you cannot guarantee “conversion” – just parsability.

Subject: Date Format Problem - I don’t think there is an answer for it

The best answer is to say that there is no truly safe way to treat dates as text. You can be pretty sure that within a single code run on a single machine, the date format will be consistent – but if there is more than one machine involved, forget it, and worse, on a single machine, should a user make a change to the date format, say, within MS Word for a single document aimed at a particular customer, the log file the user created a half-hour ago will be unreadable on the same machine. If there is only one language involved, using the month names rather than numbers will work, but then what of the French- or Spanish-language specialist in Customer Services?

If you are in control of all sides of the code – if the file you are creating comes from your stuff and is ONLY used for your stuff – then you can use Format to force a particular date format when you write the file, then parse it (rather than relying on automatic conversion) when you read it.