Forum Discussion

luissantos920's avatar
luissantos920
Copper Contributor
Oct 13, 2024

Supressing date 01-01-1900

I am creating a database view and need to format date field as yyyy-MM-dd while also supressing null dates which are showing up as 01-01-1900. The statement I am using is:

 

CAST(ISNULL(FORMAT(my_data_dte, 'yyyy-MM-dd'), '') as date) as 'My_Date',

 

I've tried various ways including IFF and CASE but had no luck 😞 

Would appreciate any suggestions. 

Thank you

  • rodgerkong's avatar
    rodgerkong
    Iron Contributor

    luissantos920 

    IIF is working, like this

    DECLARE @a DATE
    --SET @a = GETDATE()  --Run this line get value to test
    SELECT IIF(@a IS NULL, '', FORMAT(@a, 'yyyy-MM-dd'))
    • luissantos920's avatar
      luissantos920
      Copper Contributor

      rodgerkong 

       

      Hi there. It worked as suggested.

      I also had to remove CAST ( ) as it would turn field into 01-01-1900 again which makes sense.

       

      Thank you!!

       

       

Resources