Navigation:  Key Concepts > Management Topics >

SQL TIPS

Previous pageReturn to chapter overviewNext page
Show/Hide Hidden Text

POSitive DATE AND TIME CONVERSION

Clarion Dates in MSSQL

There is a procedure for returning Clarion date and time integer values into MSSQL's datetime datatype.
 
For example, it is in many ways nicer to store dates and times as a Clarion long (eg: 73838 = Feb 25, 2003 and 5400001 = 15:00), as it makes keys and mathematical calculations much easier. But, this data would be useless to any non-Clarion program, unless converted to meaningful data. This is what ds_ConvertClarionDateTime does. It takes 2 input parameters, 1 output parameter, and a return status. You can optionally convert on a date value or time value, but must pass a value of 0 (zero) into the "unwanted" parameter.

 
Example: (Calling from SQL Query Analyzer)
 
declare @rs int......................... -- return status
declare @cd int........................ -- clarion date - can be a field in a table
declare @ct int......................... -- clarion time - can be a field in a table
declare @sdt datetime.............. -- sql datetime
set @cd = 73842...................... -- March 1, 2003 - 0 if "blank"
set @ct = 5400001................... -- 15:00 - 0 if "blank"
exec @rs = ds_ConvertClarionDateTime @cd,@ct,@sdt output
if @rs = -1................................ -- Both date and time parameters are zero
...print 'Zero Date and Time!'
if @rs = 1................................. -- Integer value is greater than valid clarion date
...print 'Invalid Clarion Date!'
if @rs = 2................................. -- Integer value is greater than valid clarion time
...print 'Invalid Clarion Time!'
select @sdt as 'Returned DateTime'

 

 

Clarion Dates in Excel

If you have a CSV file or other data that contains an unformatted Clarion date, and you wish to view the date in Excel, you'll need to convert the Clarion standard date to an Excel date.

Fortunately, that's easy to do. Just create a formula in another column, subtracting 36161 from the value and formatting it as a date.

Note: Clarion standard dates and the Excel DATE() function both have an arbitrary "Day 1" - for Excel, this is 1/1/1900, while Clarion's Day 1 is 12/28/1800 (although the first usable date is Day 4, or 1/1/1801). The number 36161 is the difference in days between these two dates.