--- title: "system.db.dateFormat" description: "This function is used to format Dates nicely as strings." --- # system.db.dateFormat > This function is used to format Dates nicely as strings. This function is used in **Python Scripting**. ## Description This function is used to format dates nicely as strings. It uses a format string to guide its formatting behavior. ## Client Permission Restrictions This scripting function has no Client Permission restrictions. ## Syntax `system.db.dateFormat(date, formatPattern)` ### Parameters Type | Parameter | Description ------- | ------- | ----- Date| `date` | The Date object that you'd like to format String| `formatPattern` | A format pattern string to apply. Refer to Data Type Formatting Reference for a table of acceptable symbols. ### Returns **String** - The date as a string formatted according to the format pattern. ### Scope Gateway, Vision Client, Perspective Session ## Code Examples ```python # This example displays a message box on a button press that displays the selected date (without the time) # from a Calendar component, in a format like "Feb 3, 2009" date = event.source.parent.getComponent("Calendar").latchedDate toDisplay = system.db.dateFormat(date, "MMM d, yyyy") system.gui.messageBox("The date you selected is: %s" % toDisplay) ``` ```python # This example does the same as the one above, but also displays the time, in a format like: "Feb 3, 2009 8:01pm" date = event.source.parent.getComponent("Calendar").latchedDate toDisplay = system.db.dateFormat(date, "MMM d, yyyy hh:mm a") system.gui.messageBox("The date you selected is: %s" % toDisplay) ``` ```python # This example takes two dates from two Popup Calendar components, formats them in a manner that the database understands, # and then uses them in a SQL query to limit the results to a certain date range. startDate = event.source.parent.getComponent("StartDate").date endDate = event.source.parent.getComponent("EndDate").date startDate = system.db.dateFormat(startDate, "yyyy-MM-dd HH:mm:ss") endDate = system.db.dateFormat(endDate, "yyyy-MM-dd HH:mm:ss") query = ("SELECT * FROM mytable WHERE t_stamp >= '%s' AND t_stamp <= '%s'" % (startDate, endDate)) results = system.db.runQuery(query) event.source.parent.getComponent("Table").data = results ```