# SQLCODE -180: Invalid date, time or timestamp string

Source: https://wndsoftware.com/mainframe-errors/sqlcode-180

SQLCODE -180 (SQLSTATE 22007) means a string given to Db2 as a date, time or timestamp isn't in any format Db2 recognizes. Blank fields, wrong separators and two-digit years are the usual causes.


### Other names for this code

Also written as `SQL -180`, `SQLCODE=-180`, `SQLCODE = -180`, `db2 -180`, `sqlstate 22007`, `SQL0180N`, `db2 invalid date format`.


## What it means

Db2 stores DATE, TIME and TIMESTAMP columns in its own internal form, so programs pass them in and get them back as character strings. When Db2 turns a string into one of those types, it first checks the layout. The string has to start with a digit and have the separators in the right places. A date needs at least 8 characters and a four-digit year. Leading zeros in the month and day can be left out, and trailing blanks are ignored. If it doesn't fit any layout Db2 accepts, the statement fails with -180 and the message shows the value Db2 rejected.

For input, Db2 accepts ISO and JIS dates (2026-10-12), USA dates (10/12/2026) and EUR dates (12.10.2026), plus a LOCAL format if your site has installed a date exit. Times follow similar rules, such as 14.30.00 or 14:30:00. A timestamp is usually written 2026-10-12-14.30.00.000000.

-180 is about the shape of the string, not whether the date is real. 2026/10/12 and 20261012 both fail, because neither matches a date layout. When the shape is fine but the date can't exist, such as month 13, Db2 returns -181 instead.


## Common causes

- The host variable holds spaces or low-values because the input field was blank or the program never moved a date into it. This is the most common cause by far.
- The date uses separators Db2 doesn't accept for that layout, such as 2026/10/12 or 12-10-2026.
- The string is the wrong length, for example a two-digit year like 10/12/26, or a PIC X(8) field holding 20261012.
- A CHAR or VARCHAR column that stores dates as text is converted with DATE() or compared with a DATE, and some rows hold text that isn't a date.
- The program builds the date by stringing year, month and day fields together, and one piece is blank or the wrong length.


## How to find the problem

- Read the value in the DSNT408I message or SQLERRMC. If it looks empty, the host variable held spaces or low-values.
- Display the date host variable in hex just before the statement runs. X'40' bytes are spaces and X'00' bytes are low-values.
- If the statement has several date or time host variables, match the value in the message to the one that holds it.
- For a query over a text column, look for bad rows with a check on the separator positions, for example rows where the fifth character isn't a hyphen.


## How to fix it

- Move a valid date into the field before the SQL runs. For a missing date in a nullable column, set the indicator variable to -1 so Db2 stores a null instead.
- If the column is NOT NULL, agree on a default such as 0001-01-01 or 9999-12-31 and set it in the program. Never send blanks.
- Convert dates from other systems into ISO form, yyyy-mm-dd in a PIC X(10) field, before they reach Db2.
- Validate input dates in the program before the INSERT or UPDATE, so one bad record is rejected and reported instead of stopping the run.
- For a text column that holds dates, clean up the bad rows, or change the column to DATE so Db2 stops bad values getting in.


## What it looks like


```text
CUSTLD01 - INSERT CUST_ACCT FAILED, RECORD 004812
DSNT408I SQLCODE = -180, ERROR:  THE DATE, TIME, OR TIMESTAMP VALUE 2026/10/12 IS
         INVALID
DSNT418I SQLSTATE   = 22007 SQLSTATE RETURN CODE
```


## IBM documentation

[IBM documentation: -180](https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=codes-180). Use the documentation for your installed release.

[Report a correction to WND Software](https://wndsoftware.com/contact#message).

Technical reviewer: [Albert Joseph](https://wndsoftware.com/authors/albert-joseph), WND Software.

Last reviewed 2026-10-12 by the WND Software team. Written in our own words. For the full reference, check IBM’s Db2 for z/OS documentation for your release.


## Related codes

[SQLCODE -181 Date or time value out of range Read →](https://wndsoftware.com/mainframe-errors/sqlcode-181)
[SQLCODE -302 Input value invalid or too large Read →](https://wndsoftware.com/mainframe-errors/sqlcode-302)
[SQLCODE -305 Null value with no indicator variable Read →](https://wndsoftware.com/mainframe-errors/sqlcode-305)
[SQLCODE -206 Column name not valid Read →](https://wndsoftware.com/mainframe-errors/sqlcode-206)

## Questions


### What is the difference between -180 and -181?

-180 means Db2 can't read the layout of the string at all. -181 means the layout is fine but the value can't exist, such as 2026-02-30 or a time of 25.00.00.


### Can I insert spaces into a DATE column?

No. A DATE column holds only valid dates or, if it allows nulls, a null. Set the indicator to -1 for a missing date, or use a default value the business agrees on.


### Does the DATE precompiler option change what I can insert?

No. It controls the format Db2 uses when it returns dates to the program. Input in any of the standard formats is accepted either way.

[Db2 SQLCODEs](https://wndsoftware.com/mainframe-errors/db2-sqlcodes) · [SQLCODE -171](https://wndsoftware.com/mainframe-errors/sqlcode-171) · [SQLCODE -181](https://wndsoftware.com/mainframe-errors/sqlcode-181)

[← All error codes](https://wndsoftware.com/mainframe-errors/)
