Rectangle 27 3

If you're getting your events from a file, FullCalendar posts the start and end dates for the current week view. Take a look at this page from the official documentation: http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/

$('#calendar').fullCalendar({
    events: '/myfeed.php'
});

The URL it will use includes a query string with the start and end UNIX timestamps:

/myfeed.php?start=1262332800&end=1265011200&_=1263178646

Note: The _ parameter is automatically inserted to prevent the browser from caching the result.

If you're generating you events by function, it similiarly provides the start and end times, but they are JavaScript Date objects. See this page from the official documentation: http://arshaw.com/fullcalendar/docs/event_data/events_function/

$('#calendar').fullCalendar({
    events: function(start, end, callback) {
       //Manipulate the start and end objects
    }
});

If you're just supplying an array of event dates (as per http://arshaw.com/fullcalendar/docs/event_data/events_array/), the start and end dates are not accessible. You will need to use one of the two methods above.

Is there any way to do it client side? I could add the week start/end date to every event in the feed generation, but that seems a bit wasteful. If the start/end parameters are populated before posting there should be a way to read them should there not?

$('#calendar').fullCalendar('getView').visStart gives me the value I need :D

jquery - How do I determine the start and end date on the agendaWeek v...

jquery fullcalendar
Rectangle 27 3

Maybe the answer to this question refers to a bug in an old version of MySql because between is inclusive, which means it will grab rows between the start and end dates inclusive, not just between the start and one day before the end.

SELECT CURDATE() BETWEEN CURDATE() AND CURDATE();

The result is 1 (i.e. true). I believe the original poster problem lies with mixing up proper dates (DATE) and dates with time (DATETIME or TIMESTAMP).

SELECT NOW() BETWEEN CURDATE() AND CURDATE();
SELECT NOW() BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 DAY);

The result is 0 for the first select and 1 for the second. What happened is a DATE is equivalent to a DATETIME with zero time so unless NOW() is called exactly at midnight it will be greater than CURDATE() and fall outside of the BETWEEN statement. To prevent this test only the DATE part of a DATETIME using the DATE() function:

SELECT DATE(NOW()) BETWEEN CURDATE() AND CURDATE();

mysql - SQL between dates including start and end dates - Stack Overfl...

mysql sql
Rectangle 27 245

String.Trim() will trim all white-spaces from start and end of a string:

"   A String   ".Trim() -> "A String"

String.TrimStart() will trim all white-spaces from the start of a string:

"   A String   ".TrimStart() -> "A String   "

String.TrimEnd() will trim all white-spaces from the end of a string:

"   A String   ".TrimEnd() -> "   A String"

for the MS definition of whitespace. I met a weird behavior that .TrimEnd() doesn't work (for non-breaking space character), but in the end is just that the character not listed in documentation.

There are numerous ways to trim strings, and quite a few are bench-marked. Still, I like .Trim() as being the quickest to write and easiest to read.

c# - How to remove all white spaces from the start or end of a string?...

c# string trim removing-whitespace
Rectangle 27 22

Check this jsfiddle here. It's a working example of your problem.

<input type="text" id="dt1">
<input type="text" id="dt2">
$(document).ready(function () {
    $("#dt1").datepicker({
        dateFormat: "dd-M-yy",
        minDate: 0,
        onSelect: function () {
            var dt2 = $('#dt2');
            var startDate = $(this).datepicker('getDate');
            //add 30 days to selected date
            startDate.setDate(startDate.getDate() + 30);
            var minDate = $(this).datepicker('getDate');
            //minDate of dt2 datepicker = dt1 selected day
            dt2.datepicker('setDate', minDate);
            //sets dt2 maxDate to the last day of 30 days window
            dt2.datepicker('option', 'maxDate', startDate);
            //first day which can be selected in dt2 is selected date in dt1
            dt2.datepicker('option', 'minDate', minDate);
            //same for dt1
            $(this).datepicker('option', 'minDate', minDate);
        }
    });
    $('#dt2').datepicker({
        dateFormat: "dd-M-yy"
    });
});

As soderslatt already mentioned use the onSelect option to set the dates. Other methods i used are:

I think they're all very self explaining and the documentation helps you to understand how they work. If you want to set the date of the second datepicker to dt1's date + 1 day do the same as in this line:

startDate.setDate(startDate.getDate() + 30);

But of course add 1 day and not 30.

jQuery UI Picking a start and end date within range based on start dat...

jquery jquery-ui jquery-ui-datepicker
Rectangle 27 22

Check this jsfiddle here. It's a working example of your problem.

<input type="text" id="dt1">
<input type="text" id="dt2">
$(document).ready(function () {
    $("#dt1").datepicker({
        dateFormat: "dd-M-yy",
        minDate: 0,
        onSelect: function () {
            var dt2 = $('#dt2');
            var startDate = $(this).datepicker('getDate');
            //add 30 days to selected date
            startDate.setDate(startDate.getDate() + 30);
            var minDate = $(this).datepicker('getDate');
            //minDate of dt2 datepicker = dt1 selected day
            dt2.datepicker('setDate', minDate);
            //sets dt2 maxDate to the last day of 30 days window
            dt2.datepicker('option', 'maxDate', startDate);
            //first day which can be selected in dt2 is selected date in dt1
            dt2.datepicker('option', 'minDate', minDate);
            //same for dt1
            $(this).datepicker('option', 'minDate', minDate);
        }
    });
    $('#dt2').datepicker({
        dateFormat: "dd-M-yy"
    });
});

As soderslatt already mentioned use the onSelect option to set the dates. Other methods i used are:

I think they're all very self explaining and the documentation helps you to understand how they work. If you want to set the date of the second datepicker to dt1's date + 1 day do the same as in this line:

startDate.setDate(startDate.getDate() + 30);

But of course add 1 day and not 30.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

jQuery UI Picking a start and end date within range based on start dat...

jquery jquery-ui jquery-ui-datepicker
Rectangle 27 1

The parameters of the SUBSTR function are start and length, not start ...

In the console you can see this:

"ABCDEFGHIJKL".substr(0,4)
"ABCD"

"ABCDEFGHIJKL".substr(4,6)
"EFGHIJ"

"ABCDEFGHIJKL".substr(4,2)
"EF"
.substr(4,2)

Unexpected Result With JavaScript Substr() - Stack Overflow

javascript substr
Rectangle 27 3

I would suggest that you create a table with your 'accounting months' in it, having a start date, end date and month name columns.

You could then query this to find the row where your date is between the start and end dates and return the month name. Putting this into a scalar function would then allow it to be reusable and relatively easily updated for next years months as well.

While I agree that this would be the simplest, it's not necessarily the most sustainable!

@franglais - with just 1000 rows, you can model over 80 years. It shouldn't take very long to populate such a table. Doing it as an expression/function is probably going to be quite painful (not that I'm not trying to fathom one out :-))

@Damien_The_Unbeliever Fair enough - best way of populating the table without doing it manually?

@franglais - you might need to tell us what the rules are governing your start and end months.

Sorry, just had another look at the question and can see that you have that there already...

sql - Get month name with different month start and end dates - Stack ...

sql sql-server-2008
Rectangle 27 5

generate_series()
SELECT generate_series('2010-04-01', '2011-02-01', interval '1 month')::date

sql - Select each month between a start and end date - Stack Overflow

sql arrays postgresql date select
Rectangle 27 5

You have your logic backward. If you want seasons where a given date is in that season then your where clause should look like:

WHERE '2014-01-06' BETWEEN start AND end;

@LouieMiranda Certainly. Your original logic was checking for seasons with start days or end days between '2014-01-06' and '2014-01-06'. This is the same as saying WHERE start = '2014-01-06' OR end = '2014-01-06'. What you really wanted was any season where the date was inside that seasons start and end dates.

MySQL: Proper date range between start and end date as two fields - St...

mysql between date-range
Rectangle 27 28

Here is a generic script you can use in SQL server. just amend the start and end dates:

IF EXISTS (SELECT * FROM information_schema.tables WHERE Table_Name = 'Calendar' AND Table_Type = 'BASE TABLE')
BEGIN
DROP TABLE [Calendar]
END

CREATE TABLE [Calendar]
(
    [CalendarDate] DATETIME
)

DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = GETDATE()
SET @EndDate = DATEADD(d, 365, @StartDate)

WHILE @StartDate <= @EndDate
      BEGIN
             INSERT INTO [Calendar]
             (
                   CalendarDate
             )
             SELECT
                   @StartDate

             SET @StartDate = DATEADD(dd, 1, @StartDate)
      END

If you want a more advanced calendar here is one I found on the net a while ago:

CREATE SCHEMA Auxiliary
-- We put our auxiliary tables and stuff in a separate schema
-- One of the great new things in SQL Server 2005
go

CREATE FUNCTION Auxiliary.Computus
-- Computus (Latin for computation) is the calculation of the date of
-- Easter in the Christian calendar
-- http://en.wikipedia.org/wiki/Computus
-- I'm using the Meeus/Jones/Butcher Gregorian algorithm
(
    @Y INT -- The year we are calculating easter sunday for
)
RETURNS DATETIME
AS
BEGIN
DECLARE
@a INT,
@b INT,
@c INT,
@d INT,
@e INT,
@f INT,
@g INT,
@h INT,
@i INT,
@k INT,
@L INT,
@m INT

SET @a = @Y % 19
SET @b = @Y / 100
SET @c = @Y % 100
SET @d = @b / 4
SET @e = @b % 4
SET @f = (@b + 8) / 25
SET @g = (@b - @f + 1) / 3
SET @h = (19 * @a + @b - @d - @g + 15) % 30
SET @i = @c / 4
SET @k = @c % 4
SET @L = (32 + 2 * @e + 2 * @i - @h - @k) % 7
SET @m = (@a + 11 * @h + 22 * @L) / 451
RETURN(DATEADD(month, ((@h + @L - 7 * @m + 114) / 31)-1, cast(cast(@Y AS VARCHAR) AS Datetime)) + ((@h + @L - 7 * @m + 114) % 31))
END
GO


CREATE TABLE [Auxiliary].[Calendar] (
-- This is the calendar table
  [Date] datetime NOT NULL,
  [Year] int NOT NULL,
  [Quarter] int NOT NULL,
  [Month] int NOT NULL,
  [Week] int NOT NULL,
  [Day] int NOT NULL,
  [DayOfYear] int NOT NULL,
  [Weekday] int NOT NULL,
  [Fiscal_Year] int NOT NULL,
  [Fiscal_Quarter] int NOT NULL,
  [Fiscal_Month] int NOT NULL,
  [KindOfDay] varchar(10) NOT NULL,
  [Description] varchar(50) NULL,
  PRIMARY KEY CLUSTERED ([Date])
)
GO

ALTER TABLE [Auxiliary].[Calendar]
-- In Celkoish style I'm manic about constraints (Never use em ;-))
-- http://www.celko.com/

ADD CONSTRAINT [Calendar_ck] CHECK (  ([Year] > 1900)
AND ([Quarter] BETWEEN 1 AND 4)
AND ([Month] BETWEEN 1 AND 12)
AND ([Week]  BETWEEN 1 AND 53)
AND ([Day] BETWEEN 1 AND 31)
AND ([DayOfYear] BETWEEN 1 AND 366)
AND ([Weekday] BETWEEN 1 AND 7)
AND ([Fiscal_Year] > 1900)
AND ([Fiscal_Quarter] BETWEEN 1 AND 4)
AND ([Fiscal_Month] BETWEEN 1 AND 12)
AND ([KindOfDay] IN ('HOLIDAY', 'SATURDAY', 'SUNDAY', 'BANKDAY')))
GO




SET DATEFIRST 1;
-- I want my table to contain datedata acording to ISO 8601
-- http://en.wikipedia.org/wiki/ISO_8601
-- thus first day of a week is monday
WITH Dates(Date)
-- A recursive CTE that produce all dates between 1999 and 2020-12-31
AS
(
SELECT cast('1999' AS DateTime) Date -- SQL Server supports the ISO 8601 format so this is an unambigious shortcut for 1999-01-01
UNION ALL                            -- http://msdn2.microsoft.com/en-us/library/ms190977.aspx
SELECT (Date + 1) AS Date
FROM Dates
WHERE
Date < cast('2021' AS DateTime) -1
),

DatesAndThursdayInWeek(Date, Thursday)
-- The weeks can be found by counting the thursdays in a year so we find
-- the thursday in the week for a particular date
AS
(
SELECT
Date,
CASE DATEPART(weekday,Date)
WHEN 1 THEN Date + 3
WHEN 2 THEN Date + 2
WHEN 3 THEN Date + 1
WHEN 4 THEN Date
WHEN 5 THEN Date - 1
WHEN 6 THEN Date - 2
WHEN 7 THEN Date - 3
END AS Thursday
FROM Dates
),

Weeks(Week, Thursday)
-- Now we produce the weeknumers for the thursdays
-- ROW_NUMBER is new to SQL Server 2005
AS
(
SELECT ROW_NUMBER() OVER(partition by year(Date) order by Date) Week, Thursday
FROM DatesAndThursdayInWeek
WHERE DATEPART(weekday,Date) = 4
)
INSERT INTO Auxiliary.Calendar
SELECT
d.Date,
YEAR(d.Date) AS Year,
DATEPART(Quarter, d.Date) AS Quarter,
MONTH(d.Date) AS Month,
w.Week,
DAY(d.Date) AS Day,
DATEPART(DayOfYear, d.Date) AS DayOfYear,
DATEPART(Weekday, d.Date) AS Weekday,

-- Fiscal year may be different to the actual year in Norway the are the same
-- http://en.wikipedia.org/wiki/Fiscal_year
YEAR(d.Date) AS Fiscal_Year,
DATEPART(Quarter, d.Date) AS Fiscal_Quarter,
MONTH(d.Date) AS Fiscal_Month,

CASE
-- Holidays in Norway
-- For other countries and states: Wikipedia - List of holidays by country
-- http://en.wikipedia.org/wiki/List_of_holidays_by_country
    WHEN (DATEPART(DayOfYear, d.Date) = 1)          -- New Year's Day
    OR (d.Date = Auxiliary.Computus(YEAR(Date))-7)  -- Palm Sunday
    OR (d.Date = Auxiliary.Computus(YEAR(Date))-3)  -- Maundy Thursday
    OR (d.Date = Auxiliary.Computus(YEAR(Date))-2)  -- Good Friday
    OR (d.Date = Auxiliary.Computus(YEAR(Date)))    -- Easter Sunday
    OR (d.Date = Auxiliary.Computus(YEAR(Date))+39) -- Ascension Day
    OR (d.Date = Auxiliary.Computus(YEAR(Date))+49) -- Pentecost
    OR (d.Date = Auxiliary.Computus(YEAR(Date))+50) -- Whitmonday
    OR (MONTH(d.Date) = 5 AND DAY(d.Date) = 1)      -- Labour day
    OR (MONTH(d.Date) = 5 AND DAY(d.Date) = 17)     -- Constitution day
    OR (MONTH(d.Date) = 12 AND DAY(d.Date) = 25)    -- Cristmas day
    OR (MONTH(d.Date) = 12 AND DAY(d.Date) = 26)    -- Boxing day
    THEN 'HOLIDAY'
    WHEN DATEPART(Weekday, d.Date) = 6 THEN 'SATURDAY'
    WHEN DATEPART(Weekday, d.Date) = 7 THEN 'SUNDAY'
    ELSE 'BANKDAY'
END KindOfDay,
CASE
-- Description of holidays in Norway
    WHEN (DATEPART(DayOfYear, d.Date) = 1)            THEN 'New Year''s Day'
    WHEN (d.Date = Auxiliary.Computus(YEAR(Date))-7)  THEN 'Palm Sunday'
    WHEN (d.Date = Auxiliary.Computus(YEAR(Date))-3)  THEN 'Maundy Thursday'
    WHEN (d.Date = Auxiliary.Computus(YEAR(Date))-2)  THEN 'Good Friday'
    WHEN (d.Date = Auxiliary.Computus(YEAR(Date)))    THEN 'Easter Sunday'
    WHEN (d.Date = Auxiliary.Computus(YEAR(Date))+39) THEN 'Ascension Day'
    WHEN (d.Date = Auxiliary.Computus(YEAR(Date))+49) THEN 'Pentecost'
    WHEN (d.Date = Auxiliary.Computus(YEAR(Date))+50) THEN 'Whitmonday'
    WHEN (MONTH(d.Date) = 5 AND DAY(d.Date) = 1)      THEN 'Labour day'
    WHEN (MONTH(d.Date) = 5 AND DAY(d.Date) = 17)     THEN 'Constitution day'
    WHEN (MONTH(d.Date) = 12 AND DAY(d.Date) = 25)    THEN 'Cristmas day'
    WHEN (MONTH(d.Date) = 12 AND DAY(d.Date) = 26)    THEN 'Boxing day'
END Description

FROM DatesAndThursdayInWeek d
-- This join is for getting the week into the result set
     inner join Weeks w
     on d.Thursday = w.Thursday

OPTION(MAXRECURSION 0)
GO

CREATE FUNCTION Auxiliary.Numbers
(
@AFrom INT,
@ATo INT,
@AIncrement INT
)
RETURNS @RetNumbers TABLE
(
[Number] int PRIMARY KEY NOT NULL
)
AS
BEGIN
WITH Numbers(n)
AS
(
SELECT @AFrom AS n
UNION ALL
SELECT (n + @AIncrement) AS n
FROM Numbers
WHERE
n < @ATo
)
INSERT @RetNumbers
SELECT n from Numbers
OPTION(MAXRECURSION 0)
RETURN;
END
GO

CREATE FUNCTION Auxiliary.iNumbers
(
@AFrom INT,
@ATo INT,
@AIncrement INT
)
RETURNS TABLE
AS
RETURN(
WITH Numbers(n)
AS
(
SELECT @AFrom AS n
UNION ALL
SELECT (n + @AIncrement) AS n
FROM Numbers
WHERE
n < @ATo
)
SELECT n AS Number from Numbers
)
GO

How to create a Calendar table for 100 years in Sql - Stack Overflow

sql
Rectangle 27 5

The "lead" analytic function in Oracle can grab a value from the succeeding row as a value in the current row.

Given a series of rows returned from a query and a position of the cursor, LEAD provides access to a row at a given physical offset beyond that position.

Here, this SQL grabs start_date from the next row and subtracts end_date from the current row.

select id, term, start_date, end_date,
       lead(start_date) over (partition by id order by term) - end_date diff_in_days
from your_table;
ID TERM       START_DATE           END_DATE             DIFF_IN_DAYS
---------- ---------- -------------------- -------------------- ------------
       423 201420     26-AUG-2013 00:00:00 13-DEC-2013 00:00:00           39
       423 201430     21-JAN-2014 00:00:00 09-MAY-2014 00:00:00           36
       423 201440     14-JUN-2014 00:00:00 07-AUG-2014 00:00:00

I was just about to post the same thing... but I think you want a "PARTITION BY id" in there if I understood the question correctly.

@WumpusQ.Wumbley You're right. The question does mention "For any specific ID", so I'll add a partition by ID.

Thanks for the tip. I am thinking this should work, especially with the PARTITION BY.

oracle - PL/SQL Finding Difference Between Start and End Dates in Diff...

sql oracle date plsql
Rectangle 27 56

The answer by mprivat is correct. His point is to not try to obtain end of a day, but rather compare to "before start of next day". His idea is known as the "Half-Open" approach where a span of time has a beginning that is inclusive while the ending is exclusive.

  • The current date-time frameworks is Java (java.util.Date/Calendar and Joda-Time) both use milliseconds from the epoch. But in Java 8, the new JSR 310 java.time.* classes use nanoseconds resolution. Any code you wrote based on forcing the milliseconds count of last moment of day would be incorrect if switched to the new classes.
  • Comparing data from other sources becomes faulty if they employ other resolutions. For example, Unix libraries typically employ whole seconds, and databases such as Postgres resolve date-time to microseconds.

Joda-Time 2.3 offers a method for this very purpose, to obtain first moment of the day: withTimeAtStartOfDay(). Similarly in java.time, LocalDate::atStartOfDay.

The java.util.Date and .Calendar classes are notoriously troublesome. Avoid them.

Use either Joda-Time or, preferably, java.time. The java.time framework is the official successor for the highly successful Joda-Time library.

The java.time framework is built into Java 8 and later. Back-ported to Java 6 & 7 in the ThreeTen-Backport project, further adapted to Android in the ThreeTenABP project.

An Instant is a moment on the timeline in UTC with a resolution of nanoseconds.

Instant instant = Instant.now();

Apply a time zone to get the wall-clock time for some locality.

ZoneId zoneId = ZoneId.of( "America/Montreal" );
ZonedDateTime zdt = ZonedDateTime.ofInstant( instant , zoneId );

To get the first moment of the day go through the LocalDate class and its atStartOfDay method.

ZonedDateTime zdtStart = zdt.toLocalDate().atStartOfDay( zoneId );

Using Half-Open approach, get first moment of following day.

ZonedDateTime zdtTomorrowStart = zdtStart.plusDays( 1 );

Currently the java.time framework lacks an Interval class as described below for Joda-Time. However, the ThreeTen-Extra project extends java.time with additional classes. This project is the proving ground for possible future additions to java.time. Among its classes is Interval. Construct an Interval by passing a pair of Instant objects. We can extract an Instant from our ZonedDateTime objects.

Interval today = Interval.of( zdtStart.toInstant() , zdtTomorrowStart.toInstant() );

Joda-Time has three classes to represent a span of time in various ways: Interval, Period, and Duration. An Interval has a specific beginning and ending on the timeline of the Universe. This fits our need to represent "a day".

We call the method withTimeAtStartOfDay rather than set time of day to zeros. Because of Daylight Saving Time and other anomalies the first moment of the day may not be 00:00:00.

DateTimeZone timeZone = DateTimeZone.forID( "America/Montreal" );
DateTime now = DateTime.now( timeZone );
DateTime todayStart = now.withTimeAtStartOfDay();
DateTime tomorrowStart = now.plusDays( 1 ).withTimeAtStartOfDay();
Interval today = new Interval( todayStart, tomorrowStart );

If you must, you can convert to a java.util.Date.

java.util.Date date = todayStart.toDate();

java - How to obtain the start time and end time of a day? - Stack Ove...

java date
Rectangle 27 85

Checking what a String starts with and ends with

You can use the hasPrefix(_:) and hasSuffix(_:) methods to test equality with another String.

var str = "Hello, playground"

if str.hasPrefix("Hello") { // true
    print("Prefix exists")
}

if str.hasSuffix("ground") { // true
    print("Suffix exists")
}

In order to get the actual prefix or suffix substring, you can use one of the following methods. I recommend the first method for it's simplicity. All methods use str as

var str = "Hello, playground"
characters.prefix
characters.suffix

This is the better method in my opinion. Unlike the methods 2 below, this method will not crash if the indexes go out of bounds. It will just return all the characters in the string.

let prefix = String(str.characters.prefix(225)) // Hello, playground
let suffix = String(str.characters.suffix(623)) // Hello, playground

Of course, sometimes crashes are good because they let you know there is a problem with your code. So consider the second method below as well. It will throw an error if the index goes out of bounds.

substring(to:)
substring(from:)

Swift String indexes are tricky because they have to take into account special characters (like emoji). However once you get the index it is easy to get the prefix or suffix. (See my other answer on String.Index.)

let prefixIndex = str.index(str.startIndex, offsetBy: 5)
let prefix = str.substring(to: prefixIndex) // Hello

let suffixIndex = str.index(str.endIndex, offsetBy: -6)
let suffix = str.substring(from: suffixIndex) // ground

If you want to guard against going out of bounds, you can make an index using limitedBy (again, see this answer).

String(str.characters.prefix(5))
String(str.characters.suffix(5))
str[prefixRange]
str.substringWithRange(prefixRange)

ios - How to check what a String starts with (prefix) or ends with (su...

ios string swift
Rectangle 27 17

We had to code a check to establish if the difference between two dates, a start and end date was greater than 2 years.

Thanks to the tips above it was done as follows:

DateTime StartDate = Convert.ToDateTime("01/01/2012");
 DateTime EndDate = Convert.ToDateTime("01/01/2014");
 DateTime TwoYears = StartDate.AddYears(2);

 if EndDate > TwoYears .....

Perhaps not an actual solution to the question, but it solved my problem, so upvote :)

Date difference in years using C# - Stack Overflow

c# date datediff
Rectangle 27 17

We had to code a check to establish if the difference between two dates, a start and end date was greater than 2 years.

Thanks to the tips above it was done as follows:

DateTime StartDate = Convert.ToDateTime("01/01/2012");
 DateTime EndDate = Convert.ToDateTime("01/01/2014");
 DateTime TwoYears = StartDate.AddYears(2);

 if EndDate > TwoYears .....

Perhaps not an actual solution to the question, but it solved my problem, so upvote :)

Date difference in years using C# - Stack Overflow

c# date datediff
Rectangle 27 9

But how would I disable a range of dates? As I only have the start and end dates.

One way could be to create an array of dates based on the start and end dates that you have. Use that array in beforeShowDay to disable the range.

var startDate = "2014-06-15", // some start date
    endDate  = "2014-06-21",  // some end date
    dateRange = [];           // array to hold the range

// populate the array
for (var d = new Date(startDate); d <= new Date(endDate); d.setDate(d.getDate() + 1)) {
    dateRange.push($.datepicker.formatDate('yy-mm-dd', d));
}

// use this array 
beforeShowDay: function (date) {
    var dateString = jQuery.datepicker.formatDate('yy-mm-dd', date);
    return [dateRange.indexOf(dateString) == -1];
}

Now, you could set startDate and endDate whenever a date is selected. In the example fiddle I linked to above, the start and end dates are set whenever a date is selected in the two top inputs. The data array is populated when date is selected in the second input.

Note: The above example is additive, i.e. everytime you select a new range it gets added as disabled dates into the target. If you want to clear the existing disabled range before specifying a new range, then you could do a destroy and reattach the datepicker. (And also reset the dateRange array)

$("#dt").datepicker("destroy");
$("#dt").datepicker({ 
    dateFormat : 'yy-mm-dd',
    beforeShowDay: disableDates
});

var disableDates = function(dt) {
    var dateString = jQuery.datepicker.formatDate('yy-mm-dd', dt);
    return [dateRange.indexOf(dateString) == -1];
}
onSelect: function(dateText, inst) { 
    var date = $(this).datepicker('getDate');
    startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay());
    endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
    var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;

    addWeek($.datepicker.iso8601Week(new Date(dateText)), $.datepicker.formatDate( dateFormat, startDate, inst.settings ), $.datepicker.formatDate( dateFormat, endDate, inst.settings ));

    for (var d = new Date(startDate);
        d <= new Date(endDate);
        d.setDate(d.getDate() + 1)) {
            dateRange.push($.datepicker.formatDate('dd/mm/yyyy', d));
    }

    selectCurrentWeek();
},
beforeShowDay: disableDates,
    ...

This will keep adding the newly selected date ranges to the array and will additively keep on disabling. But, be cautioned that you will need an escape route when an already selected week is removed. In that case, you may work with multiple array which can be coalesced into one master array.

I think I've misunderstood what you're doing. As nearly ALL the dates have become disabled on load and the year is 2020. dev.driz.co.uk/week.html

@Cameron: You don't have to do this on load. See my second example. You can add the beforeshowday as an option later on.

I think all dates are getting disabled on your site because you already have a beforeshowday function in there.

Okies fixed that part, but when I choose another week, the previous week chosen becomes unselected... Any ideas why? Updated the code at the link. Thanks.

You have specified that as the defaultDate

javascript - Disable/Enable selected date range on jQuery datepicker U...

javascript jquery jquery-ui datepicker
Rectangle 27 9

But how would I disable a range of dates? As I only have the start and end dates.

One way could be to create an array of dates based on the start and end dates that you have. Use that array in beforeShowDay to disable the range.

var startDate = "2014-06-15", // some start date
    endDate  = "2014-06-21",  // some end date
    dateRange = [];           // array to hold the range

// populate the array
for (var d = new Date(startDate); d <= new Date(endDate); d.setDate(d.getDate() + 1)) {
    dateRange.push($.datepicker.formatDate('yy-mm-dd', d));
}

// use this array 
beforeShowDay: function (date) {
    var dateString = jQuery.datepicker.formatDate('yy-mm-dd', date);
    return [dateRange.indexOf(dateString) == -1];
}

Now, you could set startDate and endDate whenever a date is selected. In the example fiddle I linked to above, the start and end dates are set whenever a date is selected in the two top inputs. The data array is populated when date is selected in the second input.

Note: The above example is additive, i.e. everytime you select a new range it gets added as disabled dates into the target. If you want to clear the existing disabled range before specifying a new range, then you could do a destroy and reattach the datepicker. (And also reset the dateRange array)

$("#dt").datepicker("destroy");
$("#dt").datepicker({ 
    dateFormat : 'yy-mm-dd',
    beforeShowDay: disableDates
});

var disableDates = function(dt) {
    var dateString = jQuery.datepicker.formatDate('yy-mm-dd', dt);
    return [dateRange.indexOf(dateString) == -1];
}
onSelect: function(dateText, inst) { 
    var date = $(this).datepicker('getDate');
    startDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay());
    endDate = new Date(date.getFullYear(), date.getMonth(), date.getDate() - date.getDay() + 6);
    var dateFormat = inst.settings.dateFormat || $.datepicker._defaults.dateFormat;

    addWeek($.datepicker.iso8601Week(new Date(dateText)), $.datepicker.formatDate( dateFormat, startDate, inst.settings ), $.datepicker.formatDate( dateFormat, endDate, inst.settings ));

    for (var d = new Date(startDate);
        d <= new Date(endDate);
        d.setDate(d.getDate() + 1)) {
            dateRange.push($.datepicker.formatDate('dd/mm/yyyy', d));
    }

    selectCurrentWeek();
},
beforeShowDay: disableDates,
    ...

This will keep adding the newly selected date ranges to the array and will additively keep on disabling. But, be cautioned that you will need an escape route when an already selected week is removed. In that case, you may work with multiple array which can be coalesced into one master array.

I think I've misunderstood what you're doing. As nearly ALL the dates have become disabled on load and the year is 2020. dev.driz.co.uk/week.html

@Cameron: You don't have to do this on load. See my second example. You can add the beforeshowday as an option later on.

I think all dates are getting disabled on your site because you already have a beforeshowday function in there.

Okies fixed that part, but when I choose another week, the previous week chosen becomes unselected... Any ideas why? Updated the code at the link. Thanks.

You have specified that as the defaultDate

javascript - Disable/Enable selected date range on jQuery datepicker U...

javascript jquery jquery-ui datepicker
Rectangle 27 5

with cte as (
      select dateadd(day, 1 - day(@startdate), @startdate) as som,
             eomonth(@startdate) as eom
      union all
      select dateadd(month, 1, som), eomonth(dateadd(month, 1, som))
      from cte
      where dateadd(month, 1, som) < @enddate
     )
select *
from cte;

If you want the name of the month, then you can use datename(month, som).

note: eomonth() support begins with SQL Server 2012

months between two dates in sql server with starting and end date of e...

sql sql-server date
Rectangle 27 21

CURDATE() BETWEEN start_date AND DATE_ADD(end_date, INTERVAL 1 DAY)

mysql - SQL between dates including start and end dates - Stack Overfl...

mysql sql
Rectangle 27 5

You can join to generate_series just as easily as you select from it. Something like this should do the trick:

You'd supply the real dates you want instead of 2010-01-01 and 2013-01-01 of course.

Older versions, such 8.3, don't have a generate_series that works with timestamps but you can fake it by using generate_series to produce day offsets from an initial date:

select t.*
from generate_series(0, 1096) dt(d)
join your_table t on ('2010-01-01'::date + dt.d between t.start and t.end)

As before, adjust the 0, 1096, and '2010-01-01' to match your data.

This looks neat (I'd have to benchmark it first, of course) but I get an error using generate_series for my Postgres 8.3 installation. Do I need any extra options, extensions or libraries? I get "ERROR: function generate_series(timestamp without time zone, timestamp without time zone, interval) does not exist. HINT: No function matches the given name and argument types. You might need to add explicit type casts."

@Jens: 8.3's generate_series doesn't have a timestamp version but you can fake it as in my update.

postgresql - Postgres SQL: Getting one result per date when table has ...

sql postgresql date range