49729

how to get weekday from a given date in python?

<h3>Question</h3>

2001-10-18 I want to calculate weekday e.g. Monday, Tuesday from the date given above. is it possible in python?


<h3>Answer1:</h3>

Here is one way to do this:

dt = '2001-10-18' year, month, day = (int(x) for x in dt.split('-')) answer = datetime.date(year, month, day).weekday()
<h3>Answer2:</h3>

There is the weekday() and isoweekday() methods for datetime objects.

Python doc

来源:https://stackoverflow.com/questions/44069953/how-to-get-weekday-from-a-given-date-in-python

Recommend

  • Using HTML.TextBoxFor to loop through items in a model [duplicate]
  • How to subclass in Qt?
  • Vim的使用
  • centos7 部署镜像仓库 harbor步骤详解
  • How to format money in PostgreSQL
  • Text label next to jQuery UI slider
  • Shouldn't the error event of xmlhttprequest have an error message?
  • jQuery validate plugin : adding a custom validator to accept letters only?
  • clarify understanding of Action-event, constructor
  • Bootstrap 3.3.2 Center modal on all viewport sizes with or without vertical scrollbar
  • Can't subscribe to Push notification
  • Updating a 'master' JSON object by adding data to a subobject
  • displaying data from multiple tables in datagridview
  • JQuery Validation for Duplicates in Form Array
  • How to signing Android APK
  • Flask-Admin batch action with form
  • WPF: Run Validator on two comboboxes as the same time
  • Issue with terraform lookup
  • Reuse jQuery object from an iframe?
  • java: reading large file with charset
  • Select running balance from table credit debit columns
  • How to get delivery report for a specific contact number while sending sms to multiple contacts in a
  • Reading large text file very slow
  • GitLab Continuous Deployment to Azure Web App
  • Existing data serialized as hash produces error when upgrading to Rails 5
  • JSF validateLength question
  • Coin change recursive approach
  • How to debug component/typescript code when running Protractor
  • using vtkTimerCallback with QVTKRenderWindowInteractor not working
  • Load php page results into div with ajax with link?
  • internal javascript not works in angular2
  • How to control xtics in gnuplot
  • Excel File upload in asp.net using SqlBulkCopy
  • Set WebClient.Builder.exchangeStrategies() without losing Spring Jackson configuration
  • C++ STL stack pop operation giving segmentation fault
  • How do I add a mouse over tooltip to an Image using .DrawImage()
  • reshape/remould data frame to create normalized bar chart and pie chart
  • Google App Engine Datastore: Dealing with eventual consistency
  • Accessing Arguments, Workflow Variables from custom activities
  • ReferenceError: TextEncoder is not defined