• Resolved klingbeil

    (@klingbeil)


    Hello,
    1) Now we calculate the week of a date. So, how can we print the beginning of the week and the weekend date of this calculated date together with the day name?
    2) For example, we wrote the 5th week as number, can we do the opposite concept on which date it corresponds to the 5th week of the year?

    Thanks

    • This topic was modified 1 year, 10 months ago by klingbeil.
Viewing 15 replies - 1 through 15 (of 19 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil,

    In this case, you must calculate the date directly through an equation.

    For example, assuming that fieldname1 is a number field for entering the number of weeks. You can insert a calculated field in the form and enter the equation:

    (function(){
    var current_year = YEAR(TODAY()),
    first_day_year = '01/01/'+current_year,
    days_interval = fieldname1*7;
    
    return GETDATETIMESTRING(DATETIMESUM(first_day_year, 'dd/mm/yyyy', days_interval, 'd'), 'dd/mm/yyyy');
    })()

    Learn more about the date/time operations module by reading the following section in the plugin documentation:

    https://cff.dwbooster.com/documentation#datetime-module

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    (function(){
    var current_year = YEAR(TODAY()),
    first_day_year = '01/01/'+current_year,
    days_interval = fieldname1*7-6;
    
    return GETDATETIMESTRING(DATETIMESUM(first_day_year, 'dd/mm/yyyy', days_interval, 'd'), 'dd/mm/yyyy');
    })()

    Hello;
    In addition to this formula, we added the -6 part to calculate the week-start date.

    Alright;
    How is the week-start date of the number of days entered by the user calculated?

    In the code section above, the user calculates the week-start date by entering the week number.

    If we enter a day value, how is the week-start date calculated?
    Thanks

    It also calculates the week number of the date with WEEKNUM.
    Isn’t there a DAYNUM function?

    How do we find the day of the year of the entered date?

    • This reply was modified 1 year, 10 months ago by klingbeil.
    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    The code I proposed calculates the number of weeks that have passed since January 1st of the current year. If January 1st was Wednesday, it calculates a week from Wednesday to Wednesday.

    If you want to get the Monday date of the corresponding week, the code would be:

    (function(){
    var current_year = YEAR(TODAY()),
    first_day_year = '01/01/'+current_year,
    days_interval = fieldname1*7,
    calculated_date = DATETIMESUM(first_day_year, 'dd/mm/yyyy', days_interval, 'd'),
    week_day = WEEKDAY(calculated_date,'dd/mm/yyyy'),
    tmp;
    
    switch(week_day){
    case 1: tmp = 6; break;
    case 2: tmp = 0; break;
    case 3: tmp = 1; break;
    case 4: tmp = 2; break;
    case 5: tmp = 3; break;
    case 6: tmp = 4; break;
    case 7: tmp = 5; break;
    }
    
    return GETDATETIMESTRING(DATETIMESUM(calculated_date, 'dd/mm/yyyy', -1*tmp, 'd'), 'dd/mm/yyyy');
    })()

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    I think there was an error in your code.
    When I select the C criterion, the User enters the number of days. For example 235
    The 235th day does not write the result of the week of the year (week start date).

    It writes a fixed number, I think, it subtracts as much as the day entered from January 1, 2023.

    Form Link

    (function() {
      var btarih, tarihb, days_interval;
    
      if (fieldname16 == 'A') {
        btarih = GETDATETIMESTRING(TODAY(), 'dd/mm/yyyy');
        jQuery('#calculation-btarih').html(btarih);
        jQuery('.tarih-text').html('Tarih :');
        jQuery('.tarih-sonuc').html(btarih);
        return btarih;
      }
      if (fieldname16 == 'B') {
        var d = CONCATENATE(fieldname1,'/', fieldname2, '/', fieldname3);
    	var tarihb = GETDATETIMESTRING(DATEOBJ(d, 'dd/mm/yyyy'), 'dd/mm/yyyy');
        jQuery('#calculation-tarihb').html(tarihb);
        jQuery('.tarih-text').html('Tarih :');
        jQuery('.tarih-sonuc').html(tarihb);
        return tarihb;
      }
      
       if (fieldname16 == 'C') {
    var current_year = YEAR(TODAY()),
    first_day_year = '01/01/'+current_year,
    days_interval = fieldname1*7,
    calculated_date = DATETIMESUM(first_day_year, 'dd/mm/yyyy', days_interval, 'd'),
    week_day = WEEKDAY(calculated_date,'dd/mm/yyyy'),
    tmp;
    
    switch(week_day){
    case 1: tmp = 6; break;
    case 2: tmp = 0; break;
    case 3: tmp = 1; break;
    case 4: tmp = 2; break;
    case 5: tmp = 3; break;
    case 6: tmp = 4; break;
    case 7: tmp = 5; break;
    }
    
    return GETDATETIMESTRING(DATETIMESUM(calculated_date, 'dd/mm/yyyy', -1*tmp, 'd'), 'dd/mm/yyyy');
      } 
    
      return '';
    })();
    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    Note I sent you a hypothetical equation based on your use case description. It is not a code for copy/paste to include directly on your form. You must adjust it to your fields names and form structure.

    For example the equation has the piece of code:

    days_interval = fieldname1*7,

    But in your form, fieldname1 is a dropdown field for days selection dependent on the “B” choice in the fieldname16 field. Its value is not the number of weeks, as you mentioned in the first support thread entry.

    You have other issues in the equations. For example, you have equations that use the fieldname28 field, but there is no fieldname28 field in the form.

    If you remove a field from the form, you must fix the equations that use it.

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    So let’s wrap it up like this. Since I was working with an example on another form, some unnecessary fields were left. I’m working on sequential calculations. But they were not factors.

    I have now removed them. If I told you the situation I want to do again, we could not come to an agreement this time.

    When the user selects the C criterion, the fieldname17 field appears, this field enters the Day value. For example, I entered the day value as 25.

    What week is the 25th day of the year and I want to calculate the start and end date of that week.

    I couldn’t solve this, please don’t worry about me, I’m writing because it’s complicated.

    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    The solution depends on how you consider the weeks. For example, if the weeks are intervals of 7 days, the number entered by the user will be in the CEIL(fieldname17/7) week.

    Id January 1st is a Thursday, and you consider next Monday as the second week because the weeks are from Sunday to Saturday, the equation would be:

    
    (function(){
    var first_day = WEEKDAY('01/01/'+YEAR(), 'dd/mm/yyyy'), n = fieldname17 - (7 - first_day);
    if( 0 <= n) return CEIL(n/7)+1;
    return 1;
    })()

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    Now we found the week according to the number of days, super.
    So how do we add the week start date function of the found week?

    (function() {
    var btarih, tarihb, days_interval;
    
    if (fieldname16 == 'A') {
    btarih = GETDATETIMESTRING(TODAY(), 'dd/mm/yyyy');
    jQuery('#calculation-btarih').html(btarih);
    jQuery('.tarih-text').html('Tarih :');
    jQuery('.tarih-sonuc').html(btarih);
    return btarih;
    }
    if (fieldname16 == 'B') {
    var d = CONCATENATE(fieldname1,'/', fieldname2, '/', fieldname3);
    var tarihb = GETDATETIMESTRING(DATEOBJ(d, 'dd/mm/yyyy'), 'dd/mm/yyyy');
    jQuery('#calculation-tarihb').html(tarihb);
    jQuery('.tarih-text').html('Tarih :');
    jQuery('.tarih-sonuc').html(tarihb);
    return tarihb;
    }
    
    if (fieldname16 == 'C') {
    var first_day = WEEKDAY('01/01/'+YEAR(), 'dd/mm/yyyy'), n = fieldname17 - (7 - first_day);
    if( 0 <= n) return CEIL(n/7)+1;
    return 1;
    }
    
    return '';
    })();
    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil ,

    In this case, the process is simpler.

    
    (function(){
    var d = DATEOBJ('01/01/'+YEAR(), 'dd/mm/yyyy');
    d.setDate(d.getDate()+fieldname17);
    d.setDate(d.getDate()-d.getDay());
    return GETDATETIMESTRING(d, 'dd/mm/yyyy');
    })()

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    I think I failed, I hesitate to write to you ??

    How do I print this result?

    (function() {
      var btarih, tarihb, first_day;
    
      if (fieldname16 == 'A') {
        btarih = GETDATETIMESTRING(TODAY(), 'dd/mm/yyyy');
        jQuery('#calculation-btarih').html(btarih);
        jQuery('.tarih-text').html('Tarih :');
        jQuery('.tarih-sonuc').html(btarih);
        return btarih;
      }
      if (fieldname16 == 'B') {
        var d = CONCATENATE(fieldname1,'/', fieldname2, '/', fieldname3);
    	var tarihb = GETDATETIMESTRING(DATEOBJ(d, 'dd/mm/yyyy'), 'dd/mm/yyyy');
        jQuery('#calculation-tarihb').html(tarihb);
        jQuery('.tarih-text').html('Tarih :');
        jQuery('.tarih-sonuc').html(tarihb);
        return tarihb;
      }
      
       if (fieldname16 == 'C') {
    var first_day = WEEKDAY('01/01/'+YEAR(), 'dd/mm/yyyy'), n = fieldname17 - (7 - first_day);
    if( 0 <= n) return CEIL(n/7)+1;
        jQuery('#calculation-first_day').html(first_day);
        jQuery('.tarih-text').html('Tarih :');
        jQuery('.tarih-sonuc').html(first_day);
    return 1;
      } 
    
      return '';
    })();
    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    A return statement returns the result of the equation and stops the evaluation of subsequent lines of code. So, your equation stops here:

    if( 0 <= n) return CEIL(n/7)+1;

    The piece of code:

    if (fieldname16 == 'C') {
    var first_day = WEEKDAY('01/01/'+YEAR(), 'dd/mm/yyyy'), n = fieldname17 - (7 - first_day);
    if( 0 <= n) return CEIL(n/7)+1;
        jQuery('#calculation-first_day').html(first_day);
        jQuery('.tarih-text').html('Tarih :');
        jQuery('.tarih-sonuc').html(first_day);
    return 1;
      } 

    Might be edited as follows:

    if (fieldname16 == 'C') {
        var first_day = WEEKDAY('01/01/'+YEAR(), 'dd/mm/yyyy'), 
            n = fieldname17 - (7 - first_day), 
            result;
    
        if( 0 <= n) result = CEIL(n/7)+1;
        else result = 1;
    
        jQuery('#calculation-first_day').html(result);
        jQuery('.tarih-text').html('Tarih :');
        jQuery('.tarih-sonuc').html(result);
    } 

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    You are a super person. Thanks.

    Thread Starter klingbeil

    (@klingbeil)

    Hello,
    So how do we calculate the number of days in a year?

    DAY(‘2013-05-21’, ‘yyyy-mm-dd’)
    Result:?21

    Calculates the day of this month
    Thanks

    • This reply was modified 1 year, 10 months ago by klingbeil.
    Plugin Author codepeople

    (@codepeople)

    Hello @klingbeil

    Subtract the first day of the year from first day of next year:

    DATEDIFF('01/01/'+(YEAR()+1), '01/01/'+YEAR(), 'dd/mm/yyyy', 'd')['days']

    Please, read the documentation of the Date/Time operations module:

    https://cff.dwbooster.com/documentation#datetime-module

    Best regards.

    Thread Starter klingbeil

    (@klingbeil)

    I’m having a hard time with these date functions. I learned many of the other methods thanks to you. I’m sure I’m looking at the guide.

    In the last code section, it subtracts the date 01/01/2023 from 01/01/2024 and writes 365 in the result.

    But I want him to write 25/05/2023, which is the day of the year, that is (145) today, which I cannot do.
    I couldn’t solve the equation ??

    Criterion A part

    (function() {
      var haftabasi, d;
      if (fieldname16 == 'A') {
    	var bugun = GETDATETIMESTRING(TODAY(), 'dd/mm/yyyy');
    	var gunsayisi = DATEDIFF('01/01/'+(YEAR()+1), bugun, 'dd/mm/yyyy', 'd')['days'];
        jQuery('#calculation-gunsayisi').html(gunsayisi);
        jQuery('.gunno-text').html('Gün :');
        jQuery('.gunno-sonuc').html(gunsayisi);
        return gunsayisi;
      }
    
      if (fieldname16 == 'C') {
        haftabasi = DATEOBJ('01/01/'+YEAR(), 'dd/mm/yyyy');
        haftabasi.setDate(haftabasi.getDate()+fieldname17);
        haftabasi.setDate(haftabasi.getDate()-haftabasi.getDay()+1);
        var haftabasiString = GETDATETIMESTRING(haftabasi, 'dd/mm/yyyy');
        jQuery('#calculation-haftabasi').html(haftabasiString);
        jQuery('.gunno-text').html('Tarih :');
        jQuery('.gunno-sonuc').html(haftabasiString);
        return haftabasiString;
      }
      return '';
    })();
    
    
    (function() {
      var gunsayisi;
      if (fieldname16 == 'A') {
    	var bugun = GETDATETIMESTRING(TODAY(), 'dd/mm/yyyy');
    	var gunsayisi = DATEDIFF('01/01/'+(YEAR()+1), 'dd/mm/yyyy', 'd')['days'];
        jQuery('#calculation-gunsayisi').html(gunsayisi);
        jQuery('.gunno-text').html('Gün :');
        jQuery('.gunno-sonuc').html(gunsayisi);
        return gunsayisi;
      }
      return '';
    })();
    

    • This reply was modified 1 year, 10 months ago by klingbeil.
Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘About week calculation’ is closed to new replies.