1. Arthur Foux
  2. PowerBuilder
  3. Friday, 3 January 2020 05:58 AM UTC

Happy New Years to All and thank You to all that replied to my last question. By the way I was able to display and save the current date and time correctly. [ 12/30/2019 7:50 am ] <- field 4 

Can You help me to compare this, date and time, data field with other date and times to set the value of the next field.

Example: if field_4 > 7 am  and field_4 < 8 am then field_5, the next field = 1

              if field_4 > 8 am  and field_4 < 9 am then field_5, the next field = 2

              if field_4 > 9 am  and field_4 < 10 am then field_5, the next field = 3 etc...

 

Much Thanks For Your help.

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Sunday, 5 January 2020 15:24 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Arthur - 

Here is a PowerScript snippet that should help you perform the logic you want. Note: The logic you supplied did not specify what action to take when the time is exactly on the hour (=7:00:00, for example). To be clear, I've indicated via comments the effective time ranges.

Datetime ldt_value
Integer  li_hour, li_eventtime

// Assumes ldt_value already contains the datetime value to be checked.
li_hour = Hour(Time(ldt_value))
Choose Case li_hour
   Case 7   // 07:00-07:59:59.999999
      li_eventtime = 1
   Case 8   // 08:00-08:59:59.999999
      li_eventtime = 2
   .
   .
   Case 13  // 13:00-13:59:59.999999

   .
   .
End Choose

HTH,

John

Comment
  1. Arthur Foux
  2. Sunday, 12 January 2020 01:41 AM UTC
Grand Answer. Thank You.
  1. Helpful
There are no comments made yet.
Arthur Foux Accepted Answer Pending Moderation
  1. Sunday, 5 January 2020 05:28 AM UTC
  2. PowerBuilder
  3. # 1

I apologize for that. 

Example: if field_4 > 7 am  and field_4 < 8 am then event_time = 1

              if field_4 > 8 am  and field_4 < 9 am then event_time = 2

              if field_4 > 9 am  and field_4 < 10 am then event_time = 3 etc...

 

In other words depending on the time of day I want to set the event_time with a value.

 

again Thank You All.

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Friday, 3 January 2020 09:18 AM UTC
  2. PowerBuilder
  3. # 2

Like Miguel I'm not sure I understand all context.

In any case there are nice functions to extract individual elements for comparison:

Data Type "Extract" Functions
DateTime date(dt),  time(dt)
Date year(d),  month(d),  day(d)
dayNumber(d)
Time hour(t),  minute(t),  second(t)

Example:

DateTime ldt_start
ldt_start = dw_data.GetItemDateTime(row, "meeting_start")

choose case Hour(Time(ldt_start))
   case 7, 8
      // Early morning
   case 9, 10, 11
      // Morning
   case 12, 13
      // Lunch
   case 14 to 17
      // Afternooon
   case 18
      // Last chance
   case else
      // Out-of-office
end choose

Enjoy, /Michael

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 3 January 2020 08:11 AM UTC
  2. PowerBuilder
  3. # 3

Hi Arthur, happy new year too.

You'll have to be a bit more specific:

- what are you trying to do exactly?

- where are you trying to do this (in datawindow attribute expression? in powerscript?)

- what does "the next field is 1" mean?

 

regards

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.