Caranya adalah:
1. Buat form seperti berikut
Masukkan kontrol Date time Picker, dan textbox dengan ketentuan sebagai berikut:
Komponen | Name | Data Type |
Date Time Picker | startDate | Date |
Date Time Picker | endDate | Date |
Text Box | difference | Single Line Of text |
2. Tambahkan Rule pada field startDate:
Action: Set a field's value
Field: difference
Value:
(number(substring(../my:endDate, 9, 2)) + floor((153 * (number(substring(../my:endDate, 6, 2)) + 12 * (floor((14 - number(substring(../my:endDate, 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) * 365 + floor((number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) div 4) - floor((number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) div 100) + floor((number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) div 400) - 32045) - (number(substring(., 9, 2)) + floor((153 * (number(substring(., 6, 2)) + 12 * (floor((14 - number(substring(., 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) * 365 + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 4) - floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 100) + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 400) - 32045)Kemudian masukkan Condition berikut ini pada Rule:
startDate is not blank and endDate is not blank
3. Tambahkan Rule pada field startDate:
Action: Set a field's value
Field: difference
Value: 0
Masukkan Conditions pada Rule:
startDate is blank or endDate is blank
4. Tambahkan Rule berikut ini pada field endDate:
Action: Set a field's value
Field: difference
Value:
(number(substring(., 9, 2)) + floor((153 * (number(substring(., 6, 2)) + 12 * (floor((14 - number(substring(., 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) * 365 + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 4) - floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 100) + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 400) - 32045) - (number(substring(../my:startDate, 9, 2)) + floor((153 * (number(substring(../my:startDate, 6, 2)) + 12 * (floor((14 - number(substring(../my:startDate, 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) * 365 + floor((number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) div 4) - floor((number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) div 100) + floor((number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) div 400) - 32045)Kemudian masukkan Conditions seperti ini pada Rule:
startDate is not blank and endDate is not blank
5. Tambahkan Rule kedua pada field endDate dengan setting sebagai berikut:
Action: Set a field's value
Field: difference
Value: 0
Masukkan Conditions berikut ini pada Rule:
startDate is blank or endDate is blank
Sehingga hasilnya sebagai berikut:
6. Masukkan Rule berikut ini pada field difference:
Action: Set a field's value
Field: .
Value: 0
Kemudian tambahkan Condition pada Rule dengan setting sebagai berikut:
difference does not match pattern Custom Pattern: -{0,1}d+
Setelah melakukan langkah-langkah diatas, maka selanjutnya adalah menjalankan (preview / publish ke sharepoint). Dan sekarang kita telah mempunyai form yang bisa menghitung perbedaan 2 tanggal secara otomatis. Cara ini juga bisa digunakan di infopath 2007 maupun 2003.
0 comments:
Post a Comment