Home > Software engineering >  How to calculate no of days based on dates
How to calculate no of days based on dates

Time:11-17

so this is regarding the picture below where the flights are flying from origin and destination. What I am unable to understand is how the days are calculated, meaning how we are saying that a flight is flying on Monday or Tuesday or Web etc based on the picture below.

Flight Details

I saw that there is a gap of 1 for Flight ABC 1111 and 5 days for ABC 2222 as seen in the picture below. Gap in between

I am trying to create a sql query on generating a pdf out of the records in Database. The Database however just have CarrierCode, Orign, Destination, ValidityTo and ValidityFrom columns.

So I'd appreciate if someone will advice on how to get the flying days based on dates provided. Thank you

CodePudding user response:

Have you even tried googling?

The DateTime class has a format setting for getting the Day of the Week: (Google Search: "get the weekday from date c#") https://learn.microsoft.com/en-us/dotnet/standard/base-types/how-to-extract-the-day-of-the-week-from-a-specific-date

If its because you mean to calculate it in general, then: (Google Search: "calculate the day of the week for any date") https://www.almanac.com/how-find-day-week

CodePudding user response:

You can use the following SQL query to return the day of the week:

SELECT DATENAME(WEEKDAY, GETDATE());

Syntax: DATENAME(interval, date)

It will return the day of the week written out.

  • Related