# If (DateTime)

| **Name**    | ***If (DateTime)***                                                                                                                                                                                                                                                                 |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Syntax      | If (Boolean condition, DateTime thenValue, DateTime elseValue)                                                                                                                                                                                                                      |
| Purpose     | To evaluate a given condition and if true, return result of thenValue. Otherwise, to return the result of elseValue.                                                                                                                                                                |
| Description | Returns the value of ‘Then’ expression or ‘Else’ expression depending on the value of condition.                                                                                                                                                                                    |
| Return Type | DateTime                                                                                                                                                                                                                                                                            |
| Parameters  | <p>Condition \[System.Boolean]</p><p>thenValue \[System.DateTime] – This Parameter’s value is returned if the result of ‘condition’ parameter is true.</p><p>elseValue \[System.DateTime] - This Parameter’s value is returned if the result of ‘condition’ parameter is false.</p> |

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/0%20\(9\).png)

### **Example**

We have a *Customers* dataset which we will use to evaluate and transform the *ShipDate* field.

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/1%20\(9\).png)

In this example we will use the *Expression* object to define the condition, and a *Variables* object to define *thenValue* and *elseValue*.

Where,

Condition: *ShipDate* = “1”

*thenValue* = 1/2/2022

*elseValue* ­ = 5/7/2023

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/2%20\(9\).png)

In the output, you can see that DateTime values, 1/2/2022 and 5/7/2023, have been returned depending on whether the *ShipDate* field condition was met.

![](https://github.com/astera-software/Astera_Data_Stack_v9/blob/main/.gitbook/assets/3%20\(4\).png)
