How to display all birthday days till 2025 starting from originating year - python-3.x

from datetime import date,time,timedelta
d = int(input("Enter the year:"))
while (d < 2025):
d += 1
dt = date(month = 4, day = 6, year = d)
print(d,":",dt.strftime("%A"))
I have coded to get all my birthday days till 2025.But how to start with originating year
output:
Enter the year: 1997
1998 : Monday
1999 : Tuesday
2000 : Thursday
2001 : Friday
2002 : Saturday
2003 : Sunday
2004 : Tuesday
2005 : Wednesday
2006 : Thursday
2007 : Friday
2008 : Sunday
2009 : Monday
2010 : Tuesday
2011 : Wednesday
2012 : Friday
2013 : Saturday
2014 : Sunday
2015 : Monday
2016 : Wednesday
2017 : Thursday
2018 : Friday
2019 : Saturday
2020 : Monday
2021 : Tuesday
2022 : Wednesday
2023 : Thursday
2024 : Saturday
2025 : Sunday

Can you try by increasing the count after you're printing the date ?
from datetime import date,time,timedelta
d = int(input("Enter the year:"))
while (d < 2025):
dt = date(month = 4, day = 6, year = d)
print(d,":",dt.strftime("%A")) # print current year
d += 1 # then increment to +1

Related

Haskell How to find next day?

-- | Days of week.
data Day = Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday deriving (Eq, Show)
-- | Returns the next weekday (excluding weekend, namely Saturday and Sunday).
nextWeekday :: Day -> Day
nextWeekday day =
if x == Sunday
then let x = Monday
if x == Monday
then let x = Tuesday
if x == Tuesday
then let x = Wednesday
if x == Wednesday
then let x = Thursday
if x == Thursday
then let x = Friday
if x == Friday
then let x = Saturday
else
then let x = Sunday
This my code right now... What's wrong with this code...? How can I auto-indent the Haskell code?
An if … then … else … in Haskell always has an else clause, since you write an expression and for the two possible outcomes of the condition, it should return a value.
Furthermore you use if x == Monday, but x is not an input parameter. You also use let x = Monday, but then you need to use an in clause. While let x = Monday in x is valid, we can simply use Monday instead of working with a helper variable x.
You thus can implement this as:
nextWeekday :: Day -> Day
nextWeekday day =
if day == Sunday
then Monday
else if day == Monday
then Tuesday
else if day == Tuesday
then Wednesday
else if day == Wednesday
then Thursday
else if day == Thursday
then Friday
else if day == Friday
then Saturday
else Sunday
Often it is however better to work with pattern matching than branching, so we can implement this as:
nextWeekDay :: Day -> Day
nextWeekDay Sunday = Monday
nextWeekDay Monday = Tuesday
nextWeekDay Tuesday = Wednesday
nextWeekDay Wednesday = Thursday
nextWeekDay Thursday = Friday
nextWeekDay Friday = Saturday
nextWeekDay Saturday = Sunday

how to Get week number from specified year date in python?

I have a time-series data and i want to get the week number from the initial date
date
20180401
20180402
20180902
20190130
20190401
Things Tried
Code
df["date"]= pd.to_datetime(df.date,format='%Y%m%d')
df["week_no"]= df.date.dt.week
But the week getting reset in 2019 results in getting a common week number of 2018.
is there anything we can do in it ??
You can use this function that will calculate the difference between two days in weeks:
def Wdiff(fromdate, todate):
d = pd.to_datetime(todate) - pd.to_datetime(fromdate)
return int(d / np.timedelta64(1, 'W'))
You can create a datetime object with the specified date, then retrieve the week number using the isocalendar method:
import datetime
myDate = datetime.date(2018, 4, 1)
week = myDate.isocalendar()[1]
print(week)
You could then calculate the total number of remaining weeks in 2018, then add the total number of weeks in each year in between, and finally add the week number of the current date.
For example, this code would print the number of weeks from the 1st of April 2018 to the 6th May 2020:
import datetime
myDate = datetime.date(2018, 4, 1)
currentDate = datetime.date(2020, 5, 6)
weeks = datetime.date(myDate.year, 12, 28).isocalendar()[1] -
myDate.isocalendar()[1]
for i in range(myDate.year, currentDate.year):
weeks += datetime.date(i, 12, 28).isocalendar()[1]
weeks += currentDate.isocalendar()[1]
print(weeks)
Note that because of the way isocalendar works, the 28th of December will always be in the last week of the given year.
The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year.
You can get more information about isocalendar here: https://docs.python.org/3/library/datetime.html
To get the week number, but as a 2-digit string (with leading zero),
you can run:
df['week_no'] = df.date.dt.strftime('%W')
The result, for slightly extended source data is:
date week_no
0 2018-04-01 13
1 2018-04-02 14
2 2018-09-02 35
3 2018-12-30 52
4 2018-12-31 53
5 2019-01-01 00
6 2019-01-02 00
7 2019-01-03 00
8 2019-01-04 00
9 2019-01-05 00
10 2019-01-06 00
11 2019-01-07 01
12 2019-01-30 04
13 2019-04-01 13
Note that the last day of 2018 (monday) has week No == 53 and "initial" days
in 2019 (up to 2019-01-06 - Sunday) have week No == 00.
If you want this column as int, append .astype(int) to the above code.

Look up a date value from each cell in a column and return a year date dependent upon where date falls between two dates

I'm wanting to add formula to locate the Policy Year in each cell in column B (starting in B2) which is determined from interrogating the date shown in the corresponding cell in Column A and then checking whether it sits in a range (inception date and expiry date) D2:E5 The Policy Year sits in C2:C5 I've shown the values I'd expect the formula in the cells in column B to draw from Column C.
COLUMN A COLUMN B EXPECTED VALUE COLUMN C COLUMN D COLUMN E
2 April 2017 2016 2016 5 December 2016 4 December 2017
5 June 2017 2016 2017 5 December 2017 4 December 2018
6 December 2017 2017 2018 5 December 2018 4 December 2019
4 January 2018 2017 2019 5 December 2019 4 December 2020
6 August 2018 2017
4 December 2018 2017
29 December 2018 2018
6 March 2020 2019

Select Data based on more than one weekday name in Python

I am trying to get data for weekday Sunday and Monday, but it only give me one day's data. I can find answer for one weekday name from a question asked by somebody.
Below are the code:
import pandas as pd
df=pd.DataFrame({'CustomerID':[1,2,3,4,5,6,7,8,9,10],
'PurchaseDate':['2007-5-7','2007-6-7','2007-7-7','2007-8-7','2007-9-9','2007-10-7',
'2007-11-7','2007-12-7','2008-1-7','2008-2-7' ],
'OrderQuantity':[1,1,1,1,1,1,1,1,1,1]})
df['PurchaseDate']=pd.to_datetime(df.PurchaseDate)
df.dtypes
df.PurchaseDate.dt.weekday_name.value_counts()
df1=df[(df.PurchaseDate.dt.weekday_name==('Sunday' and 'Monday'))]
The result I got is as in the picture below:
How would I get data for Sunday and Monday?
Use Series.isin if want weekday_name Sunday OR Monday - each date cannot be Sunday and also Monday:
df1=df[(df.PurchaseDate.dt.weekday_name.isin(['Sunday','Monday']))]
print (df1)
CustomerID PurchaseDate OrderQuantity
0 1 2007-05-07 1
4 5 2007-09-09 1
5 6 2007-10-07 1
8 9 2008-01-07 1
Verify:
print (df.PurchaseDate.dt.weekday_name)
0 Monday
1 Thursday
2 Saturday
3 Tuesday
4 Sunday
5 Sunday
6 Wednesday
7 Friday
8 Monday
9 Thursday
Name: PurchaseDate, dtype: object

Excel formula to increase month by one and week in month by one

I need a formula to increase the week in month by one as well as increase the month by one.
Basically I need an ongoing list of Mondays that would follow this pattern:
Month 1 2016, Week 1 2016, Monday = 4th Jan 2016
Month 2 2016, Week 2 2016, Monday = 8th Feb 2016
Month 3 2016, Week 3 2016, Monday = 21st Mar 2016
Month 4 2016, Week 4 2016, Monday = 25th Apr 2016
Month 5 2016, Week 1 2016, Monday = 2nd May 2016
Month 6 2016, Week 2 2016, Monday = 13th Jun 2016
as below
month date_of_first_Monday how_many_Mondays Ith_Monday_request the_date_request
1/1 =Choose(Weekday(A2,2),0,6,5,4,3,2,1)+A2 =roundup((day(eomonth(a2,0))-weekday(eomonth(a2,0),3))/7,0) =if(month(a2)=1,1,if(d1+1>c2,1,d1+1)) =b2+7*(d2-1)
2/1
3/1

Resources