Dates & Time Zones
Verified against source (14)
Extensions/StringExtensions.csapplication/AbstractObject.csapplication/Functions.csUtilities/XsltFormatting.csProperties/Settings.settingsConfiguration/Abstract.Settings.xsltConfiguration/SqlPattern.csConfiguration/ObjectConfiguration.csExtensions/DateTimeOffsetExtensions.csdecision/ImportForm.csdecision/ImportForm.Fields.csProperties/Settings.settingsTables/ImportForm.sqlFunctions/TimeDimensionInterval.sql
Date columns are DATETIMEOFFSET and date properties are DateTimeOffset? (for example ImportForm.ActualCompletion). The application setting DefaultDateType is DateTimeOffset, so values whose type QBO infers from their text are treated the same way.
The one rule to remember: any date text without an offset is interpreted in the web or app server’s local time zone, using .NET’s DateTimeOffset.Parse with the server’s culture. That applies to saves, search filters, and {token} substitutions alike. By default, most QBO servers run on GMT (offset +00:00), so date text without an offset is usually stored as a GMT value.
Parsing on save
Section titled “Parsing on save”/api/{module}/save copies request parameters onto the object through SetProperties. For a DateTimeOffset? property a string is converted like this:
| Input | Result |
|---|---|
Starts with { (e.g. {today}, {now}, {firstofmonth}) |
Replaced with the server’s local date or time, with the server’s offset |
Contains z but doesn’t end with it (e.g. 2020-10-20T20:05:05Z-420) |
Parsed as UTC, then shifted to an offset of the trailing minutes (-420 → -07:00) |
| Anything else | DateTimeOffset.Parse: an explicit offset or a trailing Z is kept; otherwise the server’s local offset for that date is applied |
Strings are lower-cased before parsing, and a DateTime value (from code, not the API) becomes a DateTimeOffset with the server’s offset.
When the command runs, each date parameter is formatted with DateTimeOffset.ToString() (offset included, sub-second precision dropped) and bound as DbType.DateTimeOffset. Audit columns are filled by the application: UpdatedDate with DateTimeOffset.Now, the web server’s clock. Triggers that stamp dates with SYSDATETIMEOFFSET() use the database server’s clock and zone, which need not match.
Trace: ActualCompletion=10/11/2020
Section titled “Trace: ActualCompletion=10/11/2020”POST /api/importform/save?ID=1234&ActualCompletion=10/11/2020SavecallsSetProperties(properties, true).ActualCompletionis aDateTimeOffset?, the value is a string not starting with{and with noz, so it goes toDateTimeOffset.Parse("10/11/2020").- With an en-US culture that is October 11, 2020, 00:00, in the server’s local zone. On a GMT server (the default for most QBO servers):
2020-10-11 00:00:00 +00:00. On a US Eastern server (daylight time in October):-04:00. On US Pacific:-07:00. - Because this is an update and
ActualCompletionchanged,BeforeUpdatedchecks whether it equalsDateTime.Today(midnight today, server time).10/11/2020isn’t today, so it is kept. Had you sent today’s date, it would becomeDateTimeOffset.Now. - If
ActualCompletionhad been omitted,ImportFormCompleteOnSave(defaulttrue) sets it toDateTimeOffset.Now. - The update binds
@ActualCompletionasDateTimeOffsetfrom the string10/11/2020 12:00:00 AM +00:00, and theImportForm.ActualCompletioncolumn (DATETIMEOFFSET) stores2020-10-11 00:00:00.0000000 +00:00(on a GMT server). - The form then completes its workflow step with the same value (see Forms).
DisplayTimeZone
Section titled “DisplayTimeZone”DisplayTimeZone is an application setting, empty by default. The settings screen edits it with a picker built from format:timeZoneList() (every Windows time zone ID on the server). It is read in exactly two places, both XSLT formatting functions:
format:formatDate(date)andformat:formatDate(date, format)pass it as the target zone toformatDate(date, format, displayTimeZone).format:currentTimeZone()returns it, or the server’s standard zone name when it’s empty.
It is not used when parsing input, building SQL, grouping dimensions, or serializing API responses. There is no per-user time zone.
formatDate(date, format, displayTimeZone, ignoreTimeZone) works like this:
- Resolves keywords (
today,now,yesterday, …) with the server clock. - If the text has a time part with no offset and no
Z, parses it as aDateTimeand formats it unchanged (no conversion). - Otherwise parses a
DateTimeOffset. IfDateTimeOffsetUseLocalTime(defaulttrue) it converts to server local time, then, ifdisplayTimeZoneis set and differs from the server’s standard zone name, converts to that zone, then formats.
ignoreTimeZone (default from FormatDateIgnoreTimeZone, false) cuts the text at the first space or T and re-parses the date part. The resulting date-only value is midnight in the server zone, which step 3 still converts to displayTimeZone, so the setting does not stop a midnight value from moving to the previous evening in a zone west of the server.
| Stored value | Server zone | DisplayTimeZone |
formatDate(…, 'd') |
|---|---|---|---|
2020-10-11 00:00:00 -04:00 |
US Eastern | (empty) | 10/11/2020 |
2020-10-11 00:00:00 -04:00 |
US Eastern | Pacific Standard Time |
10/10/2020 |
2020-10-11 00:00:00 +00:00 |
GMT (default) | (empty) | 10/11/2020 |
2020-10-11 00:00:00 +00:00 |
GMT (default) | Eastern Standard Time |
10/10/2020 |
2020-10-11 00:00:00 +00:00 |
US Eastern | (empty) | 10/10/2020 (converted to server local) |
Pass a third argument to override the zone for one template: format:formatDate(@ActualCompletion, 'd', 'Eastern Standard Time').
Search filters
Section titled “Search filters”Search parameters on date columns are written into the WHERE clause as quoted literals, after Functions.DateTimeReplace(DbType.DateTimeOffset, value). For text that isn’t a {token}, that function runs DateTimeOffset.TryParse and returns ToString(), which adds the server’s offset to date text that had none:
GET /api/importform/search?ActualCompletion=-10/11/2020,10/12/2020-- on a GMT server[ImportForm].[ActualCompletion] BETWEEN '10/11/2020 12:00:00 AM +00:00' AND '10/12/2020 12:00:00 AM +00:00'The operators are ! (not equal), > (>=), < (<=), and -a,b (BETWEEN, inclusive at both ends). So a day filter covers the server’s local calendar day. Comparisons are by instant: a value saved as 2020-10-11 21:30:00 -07:00 (4:30 AM October 12 GMT) falls on October 12 for this filter. To filter on another zone’s day, send the offset: ActualCompletion=-2020-10-11T00:00:00-07:00,2020-10-11T23:59:59-07:00.
Time dimensions
Section titled “Time dimensions”Dashboards that group a date column (Dimension=ActualCompletion) join to dbo.TimeDimensionInterval(@ActualCompletionStart, @ActualCompletionEnd, @ActualCompletionIntervals) on ActualCompletion >= BeginDate AND ActualCompletion < EndDate. The function takes DATETIMEOFFSET arguments but returns BeginDate and EndDate as DATETIME, which drops the offset and keeps the server’s wall-clock time. SQL Server compares a DATETIME with a DATETIMEOFFSET as +00:00, so the buckets are the server’s calendar days treated as UTC days.
On a GMT server, the default for most QBO servers, that matches the filters. On a US Eastern server, the 2020-10-11 bucket covers 8:00 PM October 10 to 8:00 PM October 11 Eastern: a value at midnight Eastern stays in its day, but a value at 9:00 PM Eastern on October 11 lands in the 2020-10-12 bucket while a day filter for October 11 includes it.
Other server-local calculations
Section titled “Other server-local calculations”{today},{yesterday},{firstofmonth}, and the other tokens start fromDateTime.Todayon the server.format:today()and thetoday/nowkeywords informatDateuse the server clock.- Business-day arithmetic (
AddBusinessDays) converts to server local time unless a time zone ID is passed, and returns a value with the server’s offset.
Recommendations for integrations
Section titled “Recommendations for integrations”- Send ISO 8601 with an offset (
2020-10-11T14:30:00-04:00) for every date. QBO keeps what you send regardless of the server zone or culture. - For date-only business values, send midnight in the business’s zone with its offset. Avoid
Zunless the business day is a UTC day. - Leave
DisplayTimeZoneempty unless the server zone isn’t the zone readers expect, and test date-only fields in that case. On a GMT server, any US display zone shows midnight values as the previous day. - In custom SQL, group with
CAST(col AT TIME ZONE '<zone>' AS date)to report every row in one zone;CAST(col AS date)keeps the zone each value was recorded in. - Don’t send a date-only value equal to today when you mean midnight on an
ImportFormupdate; it becomes the current time.