FB II Compiler







Disk I/O














Made with FB


Get the date in mm/dd/yyyy format

Can someone show me an example of how to get the system date in mmddyyyy format? DATE$() only returns 2 digits for the year, and I need to retrofit a program I have for the new year.

Use the toolbox to get the type of string you want :
         CALL IUDATESTRING([_time],0,temp$):'         get the date right now
         CALL MOVETO(336,44):'                      where to display this at
         TEXT _geneva,10,_boldBit%,_srcOr
         CALL DRAWSTRING(temp$):'                          and show the date
0 = short date 1/10/1998
1 = long date Wednesday, February 1, 1989
2 = abbrev. date , Wed, Feb 1, 1989

I used to use this when doing apps that would run in different countries because you know what you'll get. Unlike Forrest Gump.
Mel Patrick

Try the following
LOCAL FN theLongDate$
  DIM LongDate$
  DIM osErr%
  DIM secs&
  osErr% = FN READDATETIME (secs&)
  CALL IUDATESTRING (secs&,_LongDate,LongDate$)
  CALL IUDATESTRING ([_Time],_LongDate,LongDate$)
END FN = LongDate$                                'FN theLongDate$

longDate$ = FN theLongDate$
yr$ = RIGHT$(longDate$,4)
dayMon$ = LEFT$(DATE$,6)
theDDMMYYY$ = dayMon$+yr$


DELAY 2000                                        'So you can set the results
Joe Lewis Wilkins

IUDATESTRING works pretty well as long as all you intend to do is display the date, and you're willing to use the date format that the user has selected in the "Date & Time" control panel. But it's not very reliable if you need to extract the individual date fields, because you can't count on them being in a fixed location within the string that IUDATESTRING returns. For example, the last 4 characters of the string will _probably_ be the year, but you can't guarantee that (the user might have set the display format to "yyyy-mm-dd").

If you need to get the individual date fields, use the SECS2DATE routine.
Here's an example:
DIM dateRec.14
CALL SECS2DATE([_time], @dateRec)
PRINT dateRec.month
PRINT dateRec.day
PRINT dateRec.year

The following routines can extract any part of a date (or time).

The example below uses the system's date and time record with 7 integer fields for year, month, day, hour, minute, seconds, and dayOfWeek.

FN READDATETIME is used to extract the current time in seconds (a long integer). Then that value is used by CALL SECS2DATE to get the individual parts. Specific to your case, the year is a full 4 digits; that is 1999, not 99. The other fields of the date & time result are shown in the example.

A companion routine, anotherTimeInSec& = FN DATE2SECS(@theTime) , can be used to convert other dates back to just seconds since the dawn of 'Mac Time'.

Here's some sample code to try.
DIM theTime _DateTimeRec
' the 7 fields are all integers
' year, month, day, hour, minute,second, dayOfWeek

' get current time & print its parts....
err = FN READDATETIME( TimeInSeconds& )
CALL SECS2DATE( TimeInSeconds&, @theTime )

PRINT theTime.year, theTime.month, theTime.day
PRINT theTime.hour, theTime.minute, theTime.second
PRINT theTime.dayOfWeek

' Store another date in 'Mac Time' format
theTime.year  = 2004
theTime.month = 12
theTime.day   = 31
theTime.hour      = 12    ' leave as zero if not needed
theTime.minute    = 30    ' leave as zero if not needed
theTime.second    = 15    ' leave as zero if not needed
theTime.dayOfWeek = 0     ' leave as zero if not needed
anotherTimeInSec& = FN DATE2SECS( @theTime )
I've found that storing the Mac dates themselves is more efficient that storing its parts and allows some date calculations (like in a SS or DB).
For printing, a simple conversion as above can display a 4 digit year.

Both of these sections could be made into local functions easily to meet your needs to get or store a date.
Stu Cram