logo
down
shadow

How can I display the first day of a two week period based on the current date with?


How can I display the first day of a two week period based on the current date with?

By : pablo
Date : November 21 2020, 01:01 AM
Does that help Using the ideas here for working out the difference between two dates, you can do the following:
code :
function calculatePeriodStart(targetDate) {
    
    // get first day of year
    var day1 = new Date(targetDate.getFullYear(), 0, 1);
    
    // move forward to first Saturday
    day1.setDate(7 - day1.getDay());

    //Get 2 weeks in milliseconds
    var two_weeks = 1000 * 60 * 60 * 24 * 14;
    
    // Calculate the difference in milliseconds
    var difference_ms = targetDate.getTime() - day1.getTime();
    
    // Convert back to fortnights
    var numFortnightsD = difference_ms/two_weeks;
    var numFortnights = Math.ceil(numFortnightsD);
    
    // handle if on a Saturday, so a new cycle
    if(numFortnightsD == numFortnights)
    {
        numFortnights++;
    }
    
    // add the number of fortnights
    // but take one off to get the current period
    day1.setDate(day1.getDate() + (numFortnights-1)*14);
    
    return day1;
}

// examples

console.log('-----');

// today
var today = new Date();
console.log(today + ' => ' + calculatePeriodStart(today) + ' (today)');

// just before midnight of new period
var today = new Date(2014, 11, 19, 23, 59, 59);
console.log(today + ' => ' + calculatePeriodStart(today) + ' (just before midnight of new period)');

// exactly on midnight of new period
today = new Date(2014, 11, 20);
console.log(today + ' => ' + calculatePeriodStart(today) + ' (exactly on midnight of new period)');

// just after midnight of new period
today = new Date(2014, 11, 20, 0, 0, 1)
console.log(today + ' => ' + calculatePeriodStart(today) + ' (just after midnight of new period)');

// just after midnight of new period next year
today = new Date(2015, 11, 19, 0, 0, 1);
console.log(today + ' => ' + calculatePeriodStart(today) + ' (just after midnight of new period next year)');

// earlier than 1st period in year
today = new Date(2014, 0, 2);
console.log(today + ' => ' + calculatePeriodStart(today) + ' (earlier than 1st period in year)');


Share : facebook icon twitter icon
Display the 1st, 2nd, 3rd, 4th, & 5th date of the current week in php

Display the 1st, 2nd, 3rd, 4th, & 5th date of the current week in php


By : Berrek
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further First you need to get the "current" week's Monday. To do this, I would suggest calling date("N") and see if it's 1. If it is, then now is the Monday you want. Otherwise last monday is. Pass that to strtotime to get the timestamp corresponding to the first monday of the week. Then repeatedly add 24 hours (24*3600 seconds) to get each day.
code :
$startofweek = date("N") == 1 ? time() : strtotime("last monday");
for($i=0; $i<5; $i++) {
    $day = $startofweek + 24*3600*$i;
    echo "Day ".($i+1).": ".date("d/M/Y",$day)."<br />";
}
how get the last week start date and end date based on date in current week ruby

how get the last week start date and end date based on date in current week ruby


By : user3126905
Date : March 29 2020, 07:55 AM
To fix this issue how to get the last week start date and end date based on date in current week ruby (Monday - Sunday) , You can try this way:
code :
require 'date'
=> true

date = Date.today
=> #<Date: 2015-02-04 ((2457058j,0s,0n),+0s,2299161j)>

# date.wday return week day
end_date = date-date.wday
=> #<Date: 2015-02-01 ((2457055j,0s,0n),+0s,2299161j)>

start_date = date-date.wday-6
=> #<Date: 2015-01-26 ((2457049j,0s,0n),+0s,2299161j)>
how get the last week as start date and end date based on date in current week in scrapy

how get the last week as start date and end date based on date in current week in scrapy


By : user3150866
Date : March 29 2020, 07:55 AM
should help you out You can use datetime.timedelta for that.
It has an optional weeks argument, which you can set to -1 so it will subtract seven days from the date.
code :
import datetime

def previous_week_range(date):
    start_date = date + datetime.timedelta(-date.weekday(), weeks=-1)
    end_date = date + datetime.timedelta(-date.weekday() - 1)
    return start_date, end_date

previous_week_range(datetime.date(2015, 2, 9))  # 2015-02-02, 2015-02-08
previous_week_range(datetime.date(2015, 2, 13))  # 2015-02-02, 2015-02-08
previous_week_range(datetime.date(2015, 2, 16))  # 2015-02-09, 2015-02-15
get last/current Tuesday date in Teradata based on day count of current week

get last/current Tuesday date in Teradata based on day count of current week


By : Janica Johns
Date : March 29 2020, 07:55 AM
hop of those help? There's next_day to get the following weekday, applying some logic results in:
code :
Next_Day(calendar_date - 7, 'tuesday')
How to split week start date and week end date based on custom period dates in another table

How to split week start date and week end date based on custom period dates in another table


By : user3657109
Date : March 29 2020, 07:55 AM
wish helps you I have a scenario where I need to split weeks for below period start date and end date for whole years in the calendar starting from year 1980 to 2050, period start and end dates are stored in a table. , Finally this peace of code worked, but got 3 duplicates in output....
code :
SET NOCOUNT ON;  

DECLARE @period_start_date date, @period_end_date date, @message varchar(1000),
    @period_code nvarchar(10) ;  

PRINT '-------- Starting --------';  

DECLARE vendor_cursor CURSOR FOR   
SELECT top (1) period_start_date , period_end_date, period_code from
[dbo].[MonthlyCalender] where period_start_date='2020-1-20' ORDER BY month_start_date; 

OPEN vendor_cursor  

--FETCH NEXT FROM vendor_cursor   
---INTO @month_start_date, @month_end_date,@period_code  

 ---   PRINT @month_start_date

    WHILE @@FETCH_STATUS = 0
   BEGIN
      FETCH NEXT FROM vendor_cursor   
INTO @period_start_date, @period_end_date,@period_code  

      PRINT @period_start_date
      PRINT @period_end_date
      PRINT @period_code  



declare @StartDate date


 set @StartDate = @period_start_date

 declare @EndDate date

 set @EndDate = @period_end_date

declare @pd_start_date date

set @pd_start_date = @period_start_date

declare @pd_end_date date

set @pd_end_date = @period_end_date

declare @pd_code nvarchar(10)

set @pd_code=@period_code 

 declare @DateCalc date

 declare @WeekStartDate date

 set @WeekStartDate = DATEADD(ww, DATEDIFF(ww,0,@StartDate), 0)

 set @DateCalc = @StartDate

 WHILE (@WeekStartDate <= @EndDate )

 begin

insert into testrun

   select case when @StartDate > @WeekStartDate then DatePart(ww,@StartDate) else DatePart(ww,@WeekStartDate) end as WeekNum, @StartDate as StartDate, case when DATEADD(dd, 6, @WeekStartDate) > @EndDate then @EndDate else DATEADD(dd, 6, @WeekStartDate) end as EndDate,
   @pd_start_date as pd_start_date, @pd_end_date as pd_end_date,@pd_code as pd_code;

   set @WeekStartDate = DATEADD(dd, 7, @WeekStartDate)

   set @StartDate = @WeekStartDate
 END



END;

PRINT 'Done Populating week start and end dates for given periods';


CLOSE vendor_cursor  
DEALLOCATE vendor_cursor;
Related Posts Related Posts :
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • Backbone: reverse collection order with comparator
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • Is global variable assignment atomic on NodeJS?
  • Datepicker onchangemonthyear beforeshowday
  • trying to render html files using jade but it still adresses it as a jade
  • Google Analytics - Understanding and Dissecting the Snippet: What is | | [ ];
  • Replacing "[aA09.b]." to "[aA09.b]\n" in in JavaScript
  • Why wrap a function definition in an immediate function?
  • Enable / disable jQuery script on switching to different tab in a HTML page
  • how can find return variable value outside anonymous function in node js mysql query function
  • Converting 1 to 0001 in javascript array
  • svg viewbox should not resize the text fontSize?
  • store newline character with string in a variable
  • MP4 videos in Flowplayer does not play in Windows 7 Chrome
  • jquery focusin event not firing
  • How to debug Vue application with google chrome
  • html 5 web app cache download complete javascript alert?
  • Ember.js setupController fired only once
  • How to validate a currency input
  • How to convert my Array of data to key & value pair
  • Statistics circles in CSS
  • So I wanted to make a trig solver in javascript?
  • Showing HighCharts series name on x-axis and in legend
  • In Rails, how can we pass parameters in script?
  • Build Fails: `npm rebuild node-sass --force`
  • Angular Datepicker change dateformat
  • Trying to extract data from between two sets of characters
  • Configuring Jest in WebStorm
  • Uncaught Error: Syntax error, unrecognized expression: tr.ec_portfolio_title,
  • JQuery fading in fading out continuously
  • Unexpected end of input (Line 1) and Undefined Function?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org