CA Service Management

Expand all | Collapse all

CA Service Desk date function in spell code

Jump to Best Answer
  • 1.  CA Service Desk date function in spell code

    Posted 12-16-2016 03:12 AM

    Dear all,

     

    I need some help for a couple of date calculations in spl codes.

    I want to find some unix time values for specific dates, for example tomorrow morning 08 am or first day 02 pm of upcoming month. Are there any date functions except now() for spl codes? Is it possible to make calculations by adding days / months / years to a date?

     

    Regards,

    Utku



  • 2.  Re: CA Service Desk date function in spell code
    Best Answer

    Posted 12-16-2016 03:48 AM

    Hi Utku,

    here is an example that shows all possible conversions:

    void showdate() {
         int msg_i;
         date znow, manual_date;
         znow = now();
         printf(format("int date: %d\n", (int)znow));     // unix timestamp
         printf(format("str date: %s\n", (date)znow));     // string
        
         manual_date = (date)"12/16/2016 13:40:26";     // defining date manually as string
         manual_date = (int)manual_date + (60 * 60 * 24);     // adding 24 hours without workshift
         printf(format("manual date: %s\n", (string)manual_date));
        
         send_wait(0, top_object(), "call_attr", "wrkshft", "val_by_key", "sym", "(08:30-17:30)(9x5)", 1, "sched");     // fetching workshift by name
         printf(format("shifted date: %s\n", (date)workshift_work2abs((string)msg[1], (date)now(), (duration)(60 * 60 * 9))));     // adding 9 hours using (08:30 am - 7:30 pm) workshift
    }

    output:

    D:\Scripts\bop>bop_cmd -u sd -f exec.frg showdate()
    int date: 1481877626
    str date: 12/16/2016 13:40:26
    manual date: 12/17/2016 13:40:26
    shifted date: 12/19/2016 13:40:26

     

    BONUS:

    date tomorrow_morning;
    tomorrow_morning = (date)format("%s 08:00:00", substr((string)((date)((int)now() + (int)(24 * 60 * 60))), 0, 10));
    printf(format("Tomorrow morning: %s\n", tomorrow_morning));
    // Tomorrow morning: 12/17/2016 08:00:00

     

    Regards,

    cdtj



  • 3.  Re: CA Service Desk date function in spell code

    Posted 12-19-2016 08:35 AM

    YES!! VERY usefull....

    Thank you so much cdtj.



  • 4.  Re: CA Service Desk date function in spell code

    Posted 12-20-2016 12:44 PM

    great... thanks a lot cdtj