datetimedatetime-formatdate-formatdate-formattingyellowbrick

Yellowbrick DB DateTime to Date type-casting not showing only date format (YYYY-MM-DD)


I'm working in YelloBrick DB. I want to extract only Date value from DateTime value column. In this scenario generally we use query: CAST([dateTime_Value] as DATE)

So, I'm type-casting from DateTime (timestamp) format to Date format, it's showing Date format along with extra time format (12:00:00).

This is my YelloBrick Code: (check the RED BOX area)

YelloBrick Code

So, I convert dateTime column data to String (Varchar/TEXT) format and then I use Regular-Expression(or String function will work) to Replace/Match the specific area to extract date-only part: YYYY-MM-DD. (Green BOX area of above image).

I already worked in MySQL & PostgresSQL and there this method is working fine.

MySQL-PL/pgSQL Code

My question is,

Is there any simple way to do extract date-only format ?

I don't want to use Regex or String function here . . .


Solution

  • EOD I found a meaningful solution:

    select CAST(CAST(NOW() AS DATE) AS VARCHAR(20));  
    

    This is best way, type-cast from TimeStamp to Date format.

    Other simple solution are:

    select
       CAST(TO_DATE(CAST(NOW() AS timestamp), 'YYYY-MM-DD') AS VARCHAR(20)) as sol_2,
       TO_CHAR(CAST(NOW() AS timestamp), 'YYYY-MM-DD') as sol_3;
    

    YelloBrick Validation:

    enter image description here