Hi Sean,

We have recently finished Y2K compliance testing our Mapinfo apps. The way 
mapbasic handles dates is 'interesting' and care is required to ensure that 
an application will be compliant irrespective of the set-up of the PC it is 
running on. Briefly, I would advise you to handle dates in mapbasic using 
the integer date format, YYYYMMDD. You may want to create some functions of 
your own to format date strings since FormatDate$ uses the control panel 
setings.  (Has anyone out there written any?) To quote the help file:

"The integer date format, YYYYMMDD, is not affected by how the user's 
computer is configured; therefore, you should use the integer format when 
you specify literal date values. "

Sounds like your century is being determined by the Control panel/pivot 
date? The returned values of date functions including  FormatDate$ will be 
affected by the short date format as set in the control panel.

Here are some (rather long!) notes I made at the time:

<<snip>>
Date Variable
 ----------------------
Date, stored in four bytes: two bytes for the year, one byte for the month, 
one byte for the day

Use the Dim statement to declare Date variables. For example:

Dim  d_today As Date

To assign a specific date to a date variable, use an integer of the form 
YYYYMMDD. For example:

Dim  d_start As Date

d_start = 19951231

You also can specify a date as a string. For example:

d_start = "12/31/95"

However, using strings as date values can give unpredictable results, 
because the user's computer configuration affects how the string is 
interpreted. "06/11/95" could mean June 11 or November 6.

The integer date format, YYYYMMDD, is not affected by how the user's 
computer is configured; therefore, you should use the integer format when 
you specify literal date values.


MapBasic Date Functions
Functions affected by the System Date Settings:
 -----------------------------------------------------------------------
FormatDate$ ( value )
value is a number representing the date in a YYYYMMDD format.

The FormatDate$( ) function returns a string representing a date in the 
local system format as specified by the Control Panel.

Set Format Date  { "US"  |  "Local" }

Year()
Year( date_expr )

The Year( ) function returns an integer representing the year component of 
the specified date.

Notes:
This IS affected by Control Panel date settings.  If the date expression is 
a string, this function will derive the century from the system date. To 
avoid this, make the date expression an integer.

Str$()
The Str$( ) function returns a string which represents the value of the 
specified expression.

If the expression is a Date, the output from Str$( ) depends on how the 
users computer is configured. For example, the following expression:

Str$( NumberToDate(19951231) )

might return 12/31/1995 or 1995/12/31 (etc.) depending on the date 
formatting in use on the users computer. To control how Str$( ) formats 
dates, use the Set Format statement.

Source: MapBasic 5.0 help file.

Notes:
The Set Format statement can only force the code to treat a date in the US 2 
digit year format. This is consistent but does not greatly help Y2k 
compliance.

StringToDate()
Returns a Date value, given a String.

MapBasic interprets the date string according to the date-formatting options 
that are set up on the user's computer.

Source: MapBasic 5.0 help file.

Notes:
IS affected by Control Panel date settings.


Functions NOT affected by the System Date Settings:
 ----------------------------------------------------------------------------  
 ---

CurDate( )
Returns the current date in YYYYMMDD format.

The Curdate( ) function returns a Date value representing the current date. 
The format will always be YYYYMMDD.  To change the value to a string in the 
local system format use the FormatDate$( ) or Srt$( ) functions.

NumberToDate()
NumberToDate ( numeric_date )

Where numeric_date  is an eight-digit Integer in the form YYYYMMDD (e.g. 
19951231)

Day( date_expr )
The Day( ) function returns an integer value from one to thirty-one, 
representing the day-of-the-month component of the specified date. For 
example, if the specified date is 12/17/93, the Day( ) function returns a 
value of 17.

Month( date_expr )
The Month( ) function returns an integer, representing the month component 
(one to twelve) of the specified date.


Other notes from MapBasic Help:

"To avoid the entire issue of how the user's computer is set up, call 
NumberToDate( ) instead of StringToDate( ). The NumberToDate( ) function is 
not affected by how the user's computer is set up. "

"..using strings as date values can give unpredictable results, because the 
user's computer configuration affects how the string is interpreted. 
"06/11/95" could mean June 11 or November 6. "

"The integer date format, YYYYMMDD, is not affected by how the user's 
computer is configured; therefore, you should use the integer format when 
you specify literal date values. "

"Date Operators:

date + integer When you add an Integer to a Date value, the result is a 
later Date.
date - integer When you subtract an Integer from a Date value, the result is 
an earlier Date.
date - date    When you subtract a Date value from a Date value, the result 
is an Integer, indicating the number of days between the dates."

Source: MapBasic 5.0 help file.

<<end snip>>

This is a response I received from Mapinfo in November 1998 when I asked a 
similar question:

<<snip>>

A couple of clarifications.

MapInfo 4.5 and 5.0 do not handle dates differently and Curdate() works the
same as before. We did, for good reasons, I believe, change the way date
strings are represented in MapBasic in what we call the "implicit"
conversion of a date to a string. This behavior was never documented!
However, the behavior of the explicit conversion to a string (Str$()) was
documented and did not change. We realized that MapBasic programs that did
not use Str$() might need to change but the combination of the behavior not
being documented and the necessity of the change was persuasive enough for
us.

The short answer is that anywhere you display a date you should use Str$()
as documented or the newer FormatDate$() function mentioned below. Anywhere
you convert a date to a string and are going to parse it using existing
rules you should also use Str$(). However, you should note that your code
will break on systems that are not configured to the same Control Panel
settings.  This has always been true. You are now guaranteed that parsing
of a date using the implicit conversion will work on all systems.

So, the change that occurred in MapBasic in 4.5 was the following:

Before 4.5

print CurDate() ' or any date variable or expression - date was printed in
the ordering and short format of your Windows Control panel settings

print Str$(CurDate())   ' same result

Version 4.5 and after

print CurDate() '  printed in MapInfo standard YYYYMMDD format. Note that
this format can be transferred to all locales and works correctly.

print Str$(CurDate()) - prints same as in pre 4.5

The change above was the only change made in our date to string handling
and it was done to be Y2K compliant and consistent with an international
product. Note that dates stored as formatted strings will NOT correctly
convert back to dates if the control panel settings of the system is not in
order sync with the system the string was created on!  This was regarded to
be a very bad thing for our implicit conversion to do!  This change also
affects the way dates are expressed in MIF/MID files.

We also added a new function, FormatDate$( ), which allows you to print
date strings in accordance with your Windows control panel. The output is
not only sensitive to your date ordering but to settings such as months in
abbreviated strings, etc.

The ODBC problem you mentioned was, I believe, fixed in version 5.0. We no
longer depend on any string conversions in translating an ODBC date to and
from our internal format.

Eric Blasenheim
[EMAIL PROTECTED]

<<end snip>>

Hope this helps?

Pete, Ordnance Survey, UK.

PS. Do I qualify for "the longest post ever to Mapinfo-L" award 1999??!!
 ----------
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: MI CurDate and Y2K
Date: 11 June 1999 09:30

Hi All,
     I have read the documentation from MapInfo regarding Y2K testing and
compliancy but still have some queries regarding the behaviour of the
CurDate()function.

We have been testing some MB 5.0 code for compliancy and ran the 2099-2100
rollover test. I fond that all dates returned by the FormatDate$(CurDate())
combination both before and after the rollover returned the 19/01/2038. No
matter if we use Str$(CurDate()) or just plain CurDate(), we still get the
same result.

Any ideas??

TIA

Sean McCaffrey
ERSIS Australia Pty Ltd.



 ----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]





----------------------------------------------------------------------
To unsubscribe from this list, send e-mail to [EMAIL PROTECTED] and put
"unsubscribe MAPINFO-L" in the message body, or contact [EMAIL PROTECTED]

Reply via email to