---
title: "Oracle SQL casting string as date – How works?"  
description: "Oracle SQL casting string as date – How works?"  
author: "Utpal Vishwas"  
published: 2023-07-17  
updated: 2023-07-18  
canonical: https://www.mindstick.com/forum/159138/oracle-sql-casting-string-as-date-how-works  
category: "oracle"  
tags: ["database", "sql", "string", "oracle"]  
reading_time: 2 minutes  

---

# Oracle SQL casting string as date – How works?

[Oracle](https://www.mindstick.com/articles/13016/alter-table-statement-or-command-in-oracle) [SQL](https://www.mindstick.com/articles/13115/types-of-keys-in-sql-or-oracle-database) casting [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) as [date](https://yourviews.mindstick.com/story/3869/propose-day-2024-exciting-date-ideas-for-you-and-your-partner) – How works?

## Replies

### Reply by Aryan Kumar

In Oracle SQL, you can cast a string as a date using the `CAST()` function. The `CAST()` function takes two arguments: the string to cast and the data type to cast it to. In this case, the data type to cast to is `DATE`.

For example, the following code casts the string `'2023-07-18'` as a date:

SQL

```plaintext
SELECT CAST('2023-07-18' AS DATE);
```

This code would return the date `2023-07-18`.

The `CAST()` function can also be used to cast a string in a custom format to a date. For example, the following code casts the string `'01-JAN-2023'` in the format `DD-MON-YYYY` as a date:

SQL

```plaintext
SELECT CAST('01-JAN-2023' AS DATE);
```

This code would also return the date `2023-01-01`.

The `CAST()` function is a powerful tool that you can use to cast different string formats into dates in Oracle. By using the `CAST()` function, you can ensure that your dates are stored in a consistent format.

Here are some examples of how to cast a string as a date in Oracle SQL:

SQL

```plaintext
-- Cast a string in the format "DD-MM-YYYY" as a date.
SELECT CAST('2023-07-18' AS DATE);

-- Cast a string in the format "YYYY-MM-DD" as a date.
SELECT CAST('20230718' AS DATE);

-- Cast a string in a custom format as a date.
SELECT CAST('01-JAN-2023' AS DATE);
```


---

Original Source: https://www.mindstick.com/forum/159138/oracle-sql-casting-string-as-date-how-works

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
