International Date Formats

Question: I need to get out of my provincial ways and format dates appropriate to the local preference (i.e., US, European, etc). Are there any functions I could take advantage of in ToolBook to make my path easier for localization of date formats?

The function below from our TBK Tracker product should be helpful. In early versions, we ran into problems with dates stored in an Access database on the user’s machine being in a different format than what we expected in ToolBook. This was particularly true in regions that put the day first (25/2/2014 as opposed to 2/25/2014).

to handle tbk_setSysDateFormat
	-- if not ASP mode, converts registry date 
	-- format to ToolBook equivalent
	-- else gets ToolBook date format from ASP 
	-- page

	system string s_originalSysDateFormat, 
		s_fileDir, s_tbk_iniFile, s_tbk_dbType

	local string newFormat, blkSus, errorString, aspPage
	local word offsetNum

	if s_originalSysDateFormat <> NULL 
		-- already set
		break
	end if

	if s_tbk_dbType = "ASP" -- get date format 
		-- from server-side ASP page
		aspPage = tbk_getASPPage("formatData")
		get platte_SetHTTPPostParameter("formatType", "date")
		s_originalSysDateFormat = platte_HTTPPost(aspPage)
		if s_originalSysDateFormat = null
			s_originalSysDateFormat = "mm/dd/y"
		end if
	else -- use date format of client machine
		blkSus = ASYM_blockSuspend()
		newFormat = RegistryGetKey("HKEY_CURRENT_USER\ControlPanel\International", \
		    "sShortDate")
		errorString = ASYM_restoreSuspend(blkSus)
		if (errorString <> null) OR (newFormat = null) 
		    -- unable to read date format 
			-- from registry; try win.ini
			newFormat = getWinIniVar("intl", "sShortDate")
			if (newFormat = null) OR (ASYM_isNumber(newFormat) = TRUE) 
				-- unable to read from ini file
				s_originalSysDateFormat = sysDateFormat -- default
				break
			end if
		end if

		-- year
		offsetNum = offset("yyyy", newFormat)
		if offsetNum <> 0
			chars offsetNum to (offsetNum + 3) of newFormat = "y"
		end if

		-- month
		if offset("MMM", newFormat) = 0 -- leave 
			-- alone if contains MMM; else make 
			-- lower case
			newFormat = lowerCase(newFormat)
		end if

		-- day
		-- no conversion req'd

		s_originalSysDateFormat = newFormat
	end if
end tbk_setSysDateFormat

You can skip the “ASP” part. The rest reads the registry and uses that to set the s_originalSysDateFormat system variable. When it comes time to display a date, we temporarily set sysDateFormat to this variable. The rest of the time, we set sysDateFormat to “seconds” since we use the sysDate for time tracking. You likely could just set sysDateFormat once.

About Jeff Rhodes
Jeff Rhodes is the Branch Chief, Program Office Support at the U.S. Office of Personnel Management (OPM). Prior to that, he was the Academic Chief Technical Officer at the United States Air Force Academy and previously a Senior IT Specialist in charge of SharePoint and other key systems at the Academy. Jeff was the founder and Chief Technical Officer of Platte Canyon Multimedia Software Corporation, a leader in developing commercial e-learning software. He graduated at the top of his class at the Air Force Academy, where he earned a Bachelor of Science in Electrical Engineering. Jeff received a Master’s degree in Economics from the London School of Economics, which he attended under a British Marshall Scholarship. He is the author of Creating Business Applications with Office 365: Techniques in SharePoint, PowerApps, Power BI, and More, Programming for e-Learning Developers: ToolBook, Flash, JavaScript, and Silverlight, VBTrain.Net: Creating Computer and Web Based Training with Visual Basic .NET and The ToolBook Companion. He lives in Colorado Springs with his wife Sue and is the proud father of his sons Derek and Michael.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: