CA Service Management

Expand all | Collapse all

Convert datetime to seconds in spel

Jump to Best Answer
  • 1.  Convert datetime to seconds in spel

    Posted 11-06-2017 07:46 AM

    Hi team.

    I need to convert datetime to seconds in spel as SDM does in sql server, extract some reports and make calculations on dates using second format, every report call it calculates, so I would like to do a spel function to calculate and store the value in a field so as not to make the calculation with each report generation.

    the one is: Is it possible to convert datetime to seconds in spel?

     

     

    Return Example in SPEL

    11/03 17:49:37.24 LLK85SH20073 spelsrvr 5904 SIGNIFICANT z_cr_calcula.spl 37 Retorno ktd:401702
    11/03 17:49:37.25 LLK85SH20073 spelsrvr 5904 SIGNIFICANT z_cr_calcula.spl 37 Retorno prev_time
    11/03 17:49:37.25 LLK85SH20073 spelsrvr 5904 SIGNIFICANT z_cr_calcula.spl 37 Retorno 04/18/2017 18:57:27
    11/03 17:49:37.25 LLK85SH20073 spelsrvr 5904 SIGNIFICANT z_cr_calcula.spl 37 Retorno end_time
    11/03 17:49:37.25 LLK85SH20073 spelsrvr 5904 SIGNIFICANT z_cr_calcula.spl 37 Retorno 04/18/2017 18:57:41

     

    Return Example in SQL

    ID          prev_time     end_time

    401702 1492552661 1492552647

     

     



  • 2.  Re: Convert datetime to seconds in spel
    Best Answer

    Posted 11-06-2017 08:09 AM

    Hi, 

     

    Give this a try.. Replace date with your date field. 

     

    int_date = (int)date;



  • 3.  Re: Convert datetime to seconds in spel

    Posted 11-06-2017 09:02 AM

    thanks !



  • 4.  Re: Convert datetime to seconds in spel

    Posted 11-06-2017 08:10 AM

    Just cast the datetime field to an int in Spel and you'll receive the corresponding UNIX Timestamp, which you can then use to perform calculation and return the number of seconds.



  • 5.  Re: Convert datetime to seconds in spel

    Posted 11-06-2017 08:28 AM

    I use (int)now()