NaviServer - programmable web server

[ Main Table Of Contents | Table Of Contents | Keyword Index ]

# ns_buildsqldate(n) 4.99.8 nsdb "NaviServer Module Commands"

## Name

ns_buildsqldate - SQL date and time manipulation commands

## Table Of Contents

## Synopsis

- ns_buildsqldate month day year
- ns_localsqltimestamp

## Description

The following commands build SQL dates and timestamps for inclusion in SQL queries.

## COMMANDS

ns_buildsqldate month day year

  This command builds a SQL date string out of the specified month, day, and year. The month can be the month number (1 - 12) or the full, capitalized month name (January, February, ..., December). The day must be a number from 1 - 31, and the year must be a 4-digit year (e.g., 1957). An error is returned if any of the argument values are invalid. The resulting string can be used in an SQL statement.

ns_localsqltimestamp

  This command returns a timestamp value that encodes the local time in ANSI SQL format (YYYY-MM-DD hh24:mm:ss).

## EXAMPLES

    % ns_buildsqldate "01" "15" "1929"
    1929-01-15

    % ns_buildsqldate "13" "31" "2000"
    Invalid date: 13 31 2000
    while executing ...

    % set thedate

    % ns_localsqltimestamp
    2004-06-22 23:00:27

This command is equivalent to the following:

    % ns_fmttime ns_time "%Y-%m-%d %H:%M:%S"

    % clock format ns_time -format "%Y-%m-%d %H:%M:%S"

## See Also

ns_db

## Keywords

database, date, sql, time