Home

TO_DATE and TO_TIMESTAMP should be used with a datetime format model

Description

    The TO_DATE and TO_TIMESTAMP code rules state that when using these functions, a datetime format model should be used. This ensures that the data is stored in the correct format and that the correct information is retrieved from the database. The datetime format model provides a standard way of representing dates and times, which helps to ensure accuracy and consistency across the application. It also helps to prevent errors that can occur when data is stored in an incorrect format.

Key Benefits

  • Accuracy: TO_DATE and TO_TIMESTAMP should be used with a datetime format model to ensure accuracy when converting from one data type to another.
  • Consistency: Using a datetime format model provides consistency when converting from one data type to another.
  • Efficiency: Using a datetime format model helps to ensure that the data conversion process is as efficient as possible.

 

Non-compliant Code Example

UPDATE CUSTOMERS
		SET City=city, 
			ModificationDate = TO_TIMESTAMP(date_string)   --Non compliant code (TO_DATE OR TO_TIMESTAMP is used without date-time format)
		WHERE Id = customerId;

Compliant Code Example

UPDATE CUSTOMERS
		SET City=city, 
			ModificationDate = TO_TIMESTAMP(date_string,'YYYY-MM-DD HH24:MI:SS')   --Compliant code (TO_DATE OR TO_TIMESTAMP is used with date-time format)
		WHERE Id = customerId;
Visual Expert 2024
 VEPLSQLRULE148