For date conversion, there are two function categories:
- the functions of the JavaScript library (date.toString(), date.toLocaleString(), date.getHours(), ...),
- the functions of the Neolane platform ( formatDate(date, format) ).
By convention, the first use the time zone of the machine, while the last use a time zone depending on context: usually that of the current operator, but this behavior can be modified for exports or workflows, for instance.
- new Date() creates a new Date object initialized with the current date. The date coincides with the time of the machine which the script is executed on.
- getCurrentDate() returns the current date based on the time of the database server.
The getCurrentDate() function is preferable to the first solution, specially when the date is to be compared to other dates from the database, or to be written to the database. This method reduces the risk of discrepancies (up to several minutes) linked to time differences between the application server and the database server
This typically concerns XML documents returned by the ExecuteQuery method.
Example :
var query = xtk.queryDef.create(
<queryDef schema="nms:delivery" operation="get">
<select>
<node expr="@lastModified"/>
</select>
<where>
<condition expr="@id=123456"/>
</where>
</queryDef>
)
var delivery = query.ExecuteQuery()
var lastModified = parseTimeStamp(delivery.@lastModified)
The library can be loaded using the loadLibrary function:
loadLibrary("xtk:shared/nl.js")
or using the page directive in case of a dynamic JavaScript page (JSSP):
<%@ page import="xtk:shared/nl.js" %>
Warning: you cannot use loadLibrary for all scripts. For instance, you can't change a library of JavaScript functions in an email personalization script.
Example :
This example shows the construction of a query using a literal date.
loadLibrary("xtk:shared/nl.js")
NL.require('/nl/core/shared/xtk.js')
...
var date = ...
var query = xtk.queryDef.create(
<queryDef schema="nms:delivery" operation="select">
<select>
<node expr="@id"/>
</select>
<where>
<condition expr={"@lastModified > #" + NL.XTK.formatDateTime(date) + "#"} />
</where>
</queryDef>
)
var result = query.ExecuteQuery()

