How to get yearWeek in python like we get using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear() in C#?What is the difference between String and string in C#?Cast int to enum in C#How do I check whether a file exists without exceptions?Calling an external command in PythonWhat are metaclasses in Python?How do I enumerate an enum in C#?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonDoes Python have a string 'contains' substring method?

Elegant way to prove congruence

Bringing Food from Hometown for Out-of-Town Interview?

What caused the tendency for conservatives to not support climate change regulations?

How to write a vulnerable moment without it seeming cliche or mushy?

How should I push back against my job assigning "homework"?

What should I do about a religious player who refuses to accept the existence of multiple gods in D&D?

Modern approach to radio buttons

How do I get a cleat that's stuck in a pedal, detached from the shoe, out?

If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?

How crucial is a waifu game storyline?

Infinitely many hats

Can an old DSLR be upgraded to match modern smartphone image quality

Applicants clearly not having the skills they advertise

Pros and cons of writing a book review?

Working in the USA for living expenses only; allowed on VWP?

Is having a hidden directory under /etc safe?

Why would Lupin kill Pettigrew?

Orientable with respect to complex cobordism?

what's the equivalent of helper in LWC?

Is there a rule that prohibits us from using 2 possessives in a row?

Opposite of "Squeaky wheel gets the grease"

If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?

Why is there a need to modify system call tables in Linux?

Why does my electric oven present the option of 40A and 50A breakers?



How to get yearWeek in python like we get using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear() in C#?


What is the difference between String and string in C#?Cast int to enum in C#How do I check whether a file exists without exceptions?Calling an external command in PythonWhat are metaclasses in Python?How do I enumerate an enum in C#?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonDoes Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I want to get yearWeek in python from datetime. I have used IsoCalender()[1] but it returns different week then I get in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday).



I have tried:

1) IsoCalender()[1].

2) d = datetime.datetime.strptime('2017-09-22 00:00:00.00','%Y-%m-%d %H:%M:%S.%f')
print(datetime.datetime.strftime(d,'%W'))

So For '2017-09-22 00:00:00.00' In C# I get 39 but I get 38 in python using above mentioned techniques.


Any help will be highly appretiated.










share|improve this question

















  • 1





    Did you try datetime.date(2010, 6, 16).strftime("%V") ?

    – balderman
    Mar 24 at 11:24











  • I tried it just now, but still it returns 38 for "2017-09-22 00:00:00.00" but in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday) it returns 39. please help, I am into this for 3 hours.

    – Bilal Shafqat
    Mar 24 at 11:27






  • 1





    what do you get in C# ? (I see above 39).

    – balderman
    Mar 24 at 11:28












  • string date = "2017-09-22 00:00:00.000"; DateTime dateTimez = Convert.ToDateTime(date); int week = DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(dateTimez , CalendarWeekRule.FirstDay, DayOfWeek.Monday)

    – Bilal Shafqat
    Mar 24 at 11:30











  • @balderman. Is this difference due to different implementations in these languages?

    – Bilal Shafqat
    Mar 24 at 11:36

















1















I want to get yearWeek in python from datetime. I have used IsoCalender()[1] but it returns different week then I get in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday).



I have tried:

1) IsoCalender()[1].

2) d = datetime.datetime.strptime('2017-09-22 00:00:00.00','%Y-%m-%d %H:%M:%S.%f')
print(datetime.datetime.strftime(d,'%W'))

So For '2017-09-22 00:00:00.00' In C# I get 39 but I get 38 in python using above mentioned techniques.


Any help will be highly appretiated.










share|improve this question

















  • 1





    Did you try datetime.date(2010, 6, 16).strftime("%V") ?

    – balderman
    Mar 24 at 11:24











  • I tried it just now, but still it returns 38 for "2017-09-22 00:00:00.00" but in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday) it returns 39. please help, I am into this for 3 hours.

    – Bilal Shafqat
    Mar 24 at 11:27






  • 1





    what do you get in C# ? (I see above 39).

    – balderman
    Mar 24 at 11:28












  • string date = "2017-09-22 00:00:00.000"; DateTime dateTimez = Convert.ToDateTime(date); int week = DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(dateTimez , CalendarWeekRule.FirstDay, DayOfWeek.Monday)

    – Bilal Shafqat
    Mar 24 at 11:30











  • @balderman. Is this difference due to different implementations in these languages?

    – Bilal Shafqat
    Mar 24 at 11:36













1












1








1








I want to get yearWeek in python from datetime. I have used IsoCalender()[1] but it returns different week then I get in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday).



I have tried:

1) IsoCalender()[1].

2) d = datetime.datetime.strptime('2017-09-22 00:00:00.00','%Y-%m-%d %H:%M:%S.%f')
print(datetime.datetime.strftime(d,'%W'))

So For '2017-09-22 00:00:00.00' In C# I get 39 but I get 38 in python using above mentioned techniques.


Any help will be highly appretiated.










share|improve this question














I want to get yearWeek in python from datetime. I have used IsoCalender()[1] but it returns different week then I get in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday).



I have tried:

1) IsoCalender()[1].

2) d = datetime.datetime.strptime('2017-09-22 00:00:00.00','%Y-%m-%d %H:%M:%S.%f')
print(datetime.datetime.strftime(d,'%W'))

So For '2017-09-22 00:00:00.00' In C# I get 39 but I get 38 in python using above mentioned techniques.


Any help will be highly appretiated.







c# python






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 24 at 11:20









Bilal ShafqatBilal Shafqat

446




446







  • 1





    Did you try datetime.date(2010, 6, 16).strftime("%V") ?

    – balderman
    Mar 24 at 11:24











  • I tried it just now, but still it returns 38 for "2017-09-22 00:00:00.00" but in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday) it returns 39. please help, I am into this for 3 hours.

    – Bilal Shafqat
    Mar 24 at 11:27






  • 1





    what do you get in C# ? (I see above 39).

    – balderman
    Mar 24 at 11:28












  • string date = "2017-09-22 00:00:00.000"; DateTime dateTimez = Convert.ToDateTime(date); int week = DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(dateTimez , CalendarWeekRule.FirstDay, DayOfWeek.Monday)

    – Bilal Shafqat
    Mar 24 at 11:30











  • @balderman. Is this difference due to different implementations in these languages?

    – Bilal Shafqat
    Mar 24 at 11:36












  • 1





    Did you try datetime.date(2010, 6, 16).strftime("%V") ?

    – balderman
    Mar 24 at 11:24











  • I tried it just now, but still it returns 38 for "2017-09-22 00:00:00.00" but in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday) it returns 39. please help, I am into this for 3 hours.

    – Bilal Shafqat
    Mar 24 at 11:27






  • 1





    what do you get in C# ? (I see above 39).

    – balderman
    Mar 24 at 11:28












  • string date = "2017-09-22 00:00:00.000"; DateTime dateTimez = Convert.ToDateTime(date); int week = DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(dateTimez , CalendarWeekRule.FirstDay, DayOfWeek.Monday)

    – Bilal Shafqat
    Mar 24 at 11:30











  • @balderman. Is this difference due to different implementations in these languages?

    – Bilal Shafqat
    Mar 24 at 11:36







1




1





Did you try datetime.date(2010, 6, 16).strftime("%V") ?

– balderman
Mar 24 at 11:24





Did you try datetime.date(2010, 6, 16).strftime("%V") ?

– balderman
Mar 24 at 11:24













I tried it just now, but still it returns 38 for "2017-09-22 00:00:00.00" but in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday) it returns 39. please help, I am into this for 3 hours.

– Bilal Shafqat
Mar 24 at 11:27





I tried it just now, but still it returns 38 for "2017-09-22 00:00:00.00" but in C# using DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(Date, CalendarWeekRule.FirstDay, DayOfWeek.Monday) it returns 39. please help, I am into this for 3 hours.

– Bilal Shafqat
Mar 24 at 11:27




1




1





what do you get in C# ? (I see above 39).

– balderman
Mar 24 at 11:28






what do you get in C# ? (I see above 39).

– balderman
Mar 24 at 11:28














string date = "2017-09-22 00:00:00.000"; DateTime dateTimez = Convert.ToDateTime(date); int week = DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(dateTimez , CalendarWeekRule.FirstDay, DayOfWeek.Monday)

– Bilal Shafqat
Mar 24 at 11:30





string date = "2017-09-22 00:00:00.000"; DateTime dateTimez = Convert.ToDateTime(date); int week = DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(dateTimez , CalendarWeekRule.FirstDay, DayOfWeek.Monday)

– Bilal Shafqat
Mar 24 at 11:30













@balderman. Is this difference due to different implementations in these languages?

– Bilal Shafqat
Mar 24 at 11:36





@balderman. Is this difference due to different implementations in these languages?

– Bilal Shafqat
Mar 24 at 11:36












1 Answer
1






active

oldest

votes


















1














According to ISO 8601 (cf. this draft von 2016, section 5.7.7)




A week is defined as a seven-day time interval, starting with a Monday. Week number one of the calendar year is the first week that contains at least four (4) days in that calendar year.




The documentation of Python's date.isocalendar states likewise:




[…] 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.




According to the documentation of CalendarWeekRule this equals CalendarWeekRule.FirstFourDayWeek:




Indicates that the first week of the year is the first week with four or more days before the designated first day of the week.




Whereas CalendarWeekRule.FirstDay means:




Indicates that the first week of the year starts on the first day of the year and ends before the following designated first day of the week.




In conclusion, the correct way in C# is:



DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(new DateTime(2017, 9, 22), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)


which correctly yields 38.






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323253%2fhow-to-get-yearweek-in-python-like-we-get-using-datetimeformatinfo-invariantinfo%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    According to ISO 8601 (cf. this draft von 2016, section 5.7.7)




    A week is defined as a seven-day time interval, starting with a Monday. Week number one of the calendar year is the first week that contains at least four (4) days in that calendar year.




    The documentation of Python's date.isocalendar states likewise:




    […] 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.




    According to the documentation of CalendarWeekRule this equals CalendarWeekRule.FirstFourDayWeek:




    Indicates that the first week of the year is the first week with four or more days before the designated first day of the week.




    Whereas CalendarWeekRule.FirstDay means:




    Indicates that the first week of the year starts on the first day of the year and ends before the following designated first day of the week.




    In conclusion, the correct way in C# is:



    DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(new DateTime(2017, 9, 22), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)


    which correctly yields 38.






    share|improve this answer





























      1














      According to ISO 8601 (cf. this draft von 2016, section 5.7.7)




      A week is defined as a seven-day time interval, starting with a Monday. Week number one of the calendar year is the first week that contains at least four (4) days in that calendar year.




      The documentation of Python's date.isocalendar states likewise:




      […] 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.




      According to the documentation of CalendarWeekRule this equals CalendarWeekRule.FirstFourDayWeek:




      Indicates that the first week of the year is the first week with four or more days before the designated first day of the week.




      Whereas CalendarWeekRule.FirstDay means:




      Indicates that the first week of the year starts on the first day of the year and ends before the following designated first day of the week.




      In conclusion, the correct way in C# is:



      DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(new DateTime(2017, 9, 22), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)


      which correctly yields 38.






      share|improve this answer



























        1












        1








        1







        According to ISO 8601 (cf. this draft von 2016, section 5.7.7)




        A week is defined as a seven-day time interval, starting with a Monday. Week number one of the calendar year is the first week that contains at least four (4) days in that calendar year.




        The documentation of Python's date.isocalendar states likewise:




        […] 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.




        According to the documentation of CalendarWeekRule this equals CalendarWeekRule.FirstFourDayWeek:




        Indicates that the first week of the year is the first week with four or more days before the designated first day of the week.




        Whereas CalendarWeekRule.FirstDay means:




        Indicates that the first week of the year starts on the first day of the year and ends before the following designated first day of the week.




        In conclusion, the correct way in C# is:



        DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(new DateTime(2017, 9, 22), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)


        which correctly yields 38.






        share|improve this answer















        According to ISO 8601 (cf. this draft von 2016, section 5.7.7)




        A week is defined as a seven-day time interval, starting with a Monday. Week number one of the calendar year is the first week that contains at least four (4) days in that calendar year.




        The documentation of Python's date.isocalendar states likewise:




        […] 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.




        According to the documentation of CalendarWeekRule this equals CalendarWeekRule.FirstFourDayWeek:




        Indicates that the first week of the year is the first week with four or more days before the designated first day of the week.




        Whereas CalendarWeekRule.FirstDay means:




        Indicates that the first week of the year starts on the first day of the year and ends before the following designated first day of the week.




        In conclusion, the correct way in C# is:



        DateTimeFormatInfo.InvariantInfo.Calendar.GetWeekOfYear(new DateTime(2017, 9, 22), CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday)


        which correctly yields 38.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 24 at 17:13

























        answered Mar 24 at 17:02









        ckurickuri

        1,0671510




        1,0671510





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55323253%2fhow-to-get-yearweek-in-python-like-we-get-using-datetimeformatinfo-invariantinfo%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현