Handling dates and times accurately is crucial in almost any application, and Uniface is no exception. For Uniface developers, understanding the datetime data type is fundamental to managing temporal information effectively. Let’s dive into how this powerful type works within the Uniface platform.
What is the datetime Data Type?
In Uniface, datetime is a specialized data type designed to store both date and time information within a single variable. This eliminates the need to manage separate date and time components, simplifying your code and data handling.
Its internal structure is highly precise, following a fixed format: ccyymmddhhnnsstt. Let’s break down what each segment represents:
- cc: Century (e.g., ’20’ for 20th century)
- yy: Year (e.g., ’23’ for 2023)
- mm: Month (01-12)
- dd: Day (01-31)
- hh: Hour (00-23)
- nn: Minute (00-59)
- ss: Second (00-59)
- tt: Hundredths of a second (00-99)
This granular format ensures that you can capture time down to a fraction of a second, which is vital for many business processes. You’ll encounter and use datetime when defining variables in your ProcScript or when modeling fields in your application components.
Declaring datetime Variables
Integrating datetime into your Uniface code is straightforward. Within a variables block in ProcScript, you simply declare it as you would any other data type:
variables
datetime eventTimestamp
datetime orderCreationDate
endvariables
Once declared, eventTimestamp and orderCreationDate are ready to store complete date and time values.
Uniface’s Intelligent Default Handling
One of the most user-friendly features of the datetime type is how Uniface intelligently handles incomplete or missing values. Instead of throwing errors, it applies smart default rules:
- No Value Provided: If you assign no date or time whatsoever, the
datetimevariable will be treated asNULL. - Time Only Provided: If you only specify a time (e.g., “143000”), Uniface automatically defaults the date part to the current system date.
- Incomplete Date Provided:
- A missing day defaults to
1(the first day of the month). - A missing month defaults to the current system month.
- A missing year defaults to the current system year.
- A missing day defaults to
This intelligent behavior reduces the amount of explicit handling you need to do for common scenarios, making your code cleaner and more robust.
Converting Data with the $datim Function
Often, you’ll receive date and time information as a string or a number and need to convert it into the proper datetime format for Uniface to process it correctly. This is where the powerful $datim function comes in. It’s your go-to function for these conversions.
Here’s a practical example:
variables
string inputDateString
datetime convertedDateTime
endvariables
; Assume our string holds a date without a time
inputDateString = "20240715"
; Convert the string into a datetime format
convertedDateTime = $datim(inputDateString)
; After this operation, convertedDateTime will hold '2024071500000000'.
; The time components default to midnight (00:00:00.00) because they were not specified in the input string.
The $datim function parses the input string, applies the default rules for any missing components, and returns a fully formed datetime value.
Conclusion
The datetime data type in Uniface is a versatile and essential tool for managing all your date and time requirements. With its precise internal format, straightforward declaration, intelligent default value handling, and the indispensable $datim function, you have everything you need to accurately capture, store, and manipulate temporal data in your Uniface applications. Master datetime, and you’ll master a core aspect of Uniface development!