Julian Date

Hi Experts,


I have connected to one database and I am getting date in Julian format. How can I convert them into normal date?


Thanks,

Ajeet Mahajan

Answers

  • GrantSmith
    GrantSmith Indiana πŸ”΄

    HI @user18189

    Which format are your Julian dates in? YYDDD or YYYYDDD?

    Since Julian dates count the number of days and doesn't use months you'd need some sort of DATE_ADD function call to add the number of days.

  • Ajeet_Mahajan
    Ajeet_Mahajan βšͺ️

    @GrantSmith

    Thanks for quick reply! The Julian dates are in YYYYDDD format.

    Thanks,

    Ajeet Mahajan

  • GrantSmith
    GrantSmith Indiana πŸ”΄

    @user18189

    If you're doing this via a Magic ETL2.0 you can utilize these formulas in a single formula tile: (MAGIC ETL2.0 only - I've broken them down for easier reability). julian is your date field with your Julian date. This formula assumes you'll always have a 7 digit date.

    JDAY:

    RIGHT(`julian`, 3)
    

    JYEAR:

    LEFT(`julian`, 4)
    

    GYEAR:

    DATE_FORMAT(CONCAT(`JYEAR`, '-01-01'), 'YYYY-MM-DD')
    

    GDATE:

    DATE_ADD(`GYEAR`, (`JDAY` - 1))
    


    Alternatively if you want to do this in a beast mode or want a condensed version for your formula tile you can do this:

    DATE_ADD(DATE_FORMAT(CONCAT(LEFT(`julian`, 4), '-01-01'), 'YYYY-MM-DD'), (RIGHT(`julian`, 3) - 1))
    


    To break down the logic. I'm splitting out the days and years, then calculating the first of the year. Once I have the first of the year I'll then add the specific number of days to the first of the year (minus 1 since we're 1 based).


    If you don't have Magic ETL 2.0 (in beta) talk to your CSM or alternatively use magic 1.0 tiles to get the left and right values from your julian date, figure the first of the year for your julian date, add the days to that date.

    Something like this should work (copy and paste into your magic ETL 1.0 dataflow)

    {"contentType":"domo/dataflow-actions","data":[{"name":"String Operations","id":"b4919418-af27-4d33-ba57-5337b66ca10a","type":"StringCalculator","gui":{"x":456,"y":120},"dependsOn":["302bdd61-b1d8-41f9-b935-bfa893f48562"],"removeByDefault":false,"notes":[],"calculations":[{"calcType":"SUBSTR_RL","constantB":{"value":"4","type":"LONG"},"constantC":{"value":"LEFT","type":"STRING"},"fieldA":"julian","fieldName":"JYEAR"},{"calcType":"SUBSTR_RL","constantB":{"value":"3","type":"LONG"},"constantC":{"value":"RIGHT","type":"STRING"},"fieldA":"julian","fieldName":"JDAY"}]},{"name":"Combine Columns","id":"e7d3dcda-71ee-4b69-a75a-ddcefd7858d5","type":"ConcatFields","gui":{"x":672,"y":120},"dependsOn":["e21f76c7-59f8-49b3-aada-891e70fbe989"],"removeByDefault":false,"notes":[],"separator":"-","targetFieldName":"GSTART","removeSelectedFields":true,"fields":[{"name":"JYEAR"},{"name":"GMONTH"},{"name":"GDAY"}]},{"name":"Add Constants 1","id":"e21f76c7-59f8-49b3-aada-891e70fbe989","type":"Constant","gui":{"x":576,"y":120},"dependsOn":["b4919418-af27-4d33-ba57-5337b66ca10a"],"removeByDefault":false,"notes":[],"fields":[{"name":"GDAY","type":"STRING","value":"01"},{"name":"GMONTH","type":"STRING","value":"01"}]},{"name":"Set Column Type","id":"5cf87171-de0e-4efd-a6bb-ac6ea4af627c","type":"Metadata","gui":{"x":768,"y":120},"dependsOn":["e7d3dcda-71ee-4b69-a75a-ddcefd7858d5"],"removeByDefault":false,"notes":[],"fields":[{"name":"GSTART","type":"DATE","dateFormat":"YEAR_FIRST"},{"name":"JDAY","type":"LONG"}]},{"name":"Date Operations","id":"f7af926d-8cbe-476b-aa27-0fb02863aaaf","type":"DateCalculator","gui":{"x":888,"y":120},"dependsOn":["5cf87171-de0e-4efd-a6bb-ac6ea4af627c"],"removeByDefault":false,"notes":[],"calculations":[{"fieldName":"Gregorian 1","calcType":"ADD_SUBTRACT_DATE","fieldA":"GSTART","fieldB":"JDAY","constantC":{"type":"STRING","value":"DAYS"}}]}]}
    
  • Ajeet_Mahajan
    Ajeet_Mahajan βšͺ️

    @GrantSmith Thanks for replying!

  • GrantSmith
    GrantSmith Indiana πŸ”΄

    Hi @Ajeet_Mahajan

    Did that solve your problem? If so can you accept the answer so it's easier for others to find the solution in the future? Thanks!