#๐Ÿ”’ Is there a way to convert time from 12 hours to 24 hours format in a single expression?

11 messages ยท Page 1 of 1 (latest)

ebon igloo
#

assuming only the hours are to be converted, is there a way to do it in 1 expression? the best I came up is with an if statement, two elif statements and then another else statement

dense quiverBOT
#

@ebon igloo

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

swift abyss
#

It's always possible to do something like that, but the result will likely be ugly and less readable.

ebon igloo
#

thought so, it isn't possible to do one that covers all of the edge cases

obsidian cairn
ebon igloo
#

can't use libraries, the input is the form "XX PM" or "XX AM"

#

did this and it worked time_in_hrs = int(time[:2]) % 12 + (12 if 'PM' in time else 0)

swift abyss
dense quiverBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.