PowerBuilder Function Relative DateTime gf_relative_datetime
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
///////////////////////////////////////////////////////////////////////////////////////////////////////////// // // Function Name : gf_relative_datetime // Argument Name : adtm_start, Arg Type : DateTime, Pass By : Value // al_offset, Arg Type : Long, Pass By : Value // Return Type : Datetime // Relative datetime. // If any argument's value is NULL, function returns NULL. // If any argument's value is Invalid, function returns 1900-01-01. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Description: Given a datetime, find the relative datetime +/- n seconds /////////////////////////////////////////////////////////////////////////////////////////////////////////////// DateTime ldt_null Date ld_sdate Time lt_stime Long ll_date_adjust Long ll_time_adjust, ll_time_test //Check parameters If IsNull(adtm_start) Or IsNull(al_offset) Then SetNull(ldt_null) Return ldt_null End If //Check for invalid date If Not f_Is_Valid_DateTime(adtm_start) Then Return ldt_null End If //Initialize date and time portion ld_sdate = Date(adtm_start) lt_stime = Time(adtm_start) //Find out how many days are contained //Note: 86400 is # of seconds in a day ll_date_adjust = al_offset / 86400 ll_time_adjust = Mod(al_offset, 86400) //Adjust date portion ld_sdate = RelativeDate(ld_sdate, ll_date_adjust) //Adjust time portion // Allow for time adjustments periods crossing over days // Check for time rolling forwards a day If ll_time_adjust > 0 Then ll_time_test = SecondsAfter(lt_stime,Time('23:59:59')) If ll_time_test < ll_time_adjust Then ld_sdate = RelativeDate(ld_sdate,1) ll_time_adjust = ll_time_adjust - ll_time_test -1 lt_stime = Time('00:00:00') End If lt_stime = RelativeTime(lt_stime, ll_time_adjust) //Check for time rolling backwards a day ElseIf ll_time_adjust < 0 Then ll_time_test = SecondsAfter(lt_stime,Time('00:00:00')) If ll_time_test > ll_time_adjust Then ld_sdate = RelativeDate(ld_sdate,-1) ll_time_adjust = ll_time_adjust - ll_time_test +1 lt_stime = Time('23:59:59') End If lt_stime = RelativeTime(lt_stime, ll_time_adjust) End If Return(DateTime(ld_sdate,lt_stime)) |
Good Luck!
Thanks! We have a PowerBuilder app that is integral to our business. Finding online help for changes I need to make can be a challenge. I have bookmarked your page, it’s gold 🙂