Error - function missing required argument 'month' (pos 2), is displayed when trying to fetch time in fixed format

anaghapramesh

I am trying to fetch the time in the following format, but I'm getting error that function is missing required argument for 'month'. It would be a great help if someone could resolve this small confusion.

import datetime
startTimeList = ['drwxr-xr-x  3 plan 4096 Mar 21 02:00 file_listener', 'ksh', '010001', '0\n']
startTimeStr = int(startTimeList[2])
print(startTimeStr)
startTimeStr = datetime.datetime(startTimeStr)
startTime = startTimeStr.strftime("%I:%M:%S %p")
print(startTime)

Expected Output:

010001
01:00:01 AM

Error Displayed:

function missing required argument 'month' (pos 2)
mkrieger1

Converting startTimeList[2] to an integer was not helping you, as you needed to convert it back to a string again.

datetime.datetime expects integer arguments year, month, day, which is not what you wanted to do.

You meant to use datetime.datetime.strptime to parse the string '010001' into a datetime.datetime object, which you can then convert to a differently formatted string with strftime again:

import datetime

startTimeList = ['drwxr-xr-x  3 plan 4096 Mar 21 02:00 file_listener', 'ksh', '010001', '0\n']
startTimeStr = startTimeList[2]
print(startTimeStr)

startTime = datetime.datetime.strptime(startTimeStr, "%H%M%S")
startTimeResult = startTime.strftime("%I:%M:%S %p")
print(startTimeResult)

It gives you 01:00:01 AM however, since it has no way of knowing that 010001 means a pm time.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Error while calling python function, TypeError: returnbook() missing 1 required positional argument: 'self'

I'm getting JavaScript error "d.getMonth is not a function" when trying to format a date using d3.time.format

Function missing 1 required positional argument

ForeignKey missing required positional argument on_delete when trying to create a Django migration

Django TypeError missing 1 required positional argument when trying to use form input in another function

TypeError: open() missing required argument 'file' (pos 1)

I am getting error when i call function def because_you_watched error is sample() missing 1 required positional argument: 'k'

Python TypeError: UMat() missing required argument 'ranges' (pos 2)

Run Time Error '424' object required when calling function VBA

Error lambda missing 1 required positional argument when using with QPushButton

ERROR: typeerror when() missing 1 required positional argument 'value' in PySpark

How can i try to read to topic in kafka when i am getting an error as Missing required argument "[topic]"

TypeError: get() missing 1 required positional argument: 'url' error in function SOLVED

Got "function missing required argument 'month' (pos 2)" error while adding a DateField to models.py

Function in Class error: TypeError: function() missing 1 required positional argument:

function model() missing 1 required positional argument

Python using lamda function error missing 1 required positional argument: 'event'

Flutter (Dart) only gives me a warning instead of an error during a missing required function argument

NeutralinoJS: error: missing required argument 'name'

Missing argument 1 for function error

TypeError: Required argument 'dest' (pos 2) not found

Getting missing positional argument error when trying to define middleware in Django

timezone() missing required argument 'offset' (pos 1) in models.py while trying to migrate, what is the reason?

Function always missing 1 required positional argument when stored in a list

missing 1 required positional argument for a function

Getting Error "TypeError: get_week_of_month() missing 2 required positional arguments: 'month' and 'day' while tranforming date to week

missing ) after argument list, When trying to call JS function onclick

Parse error when trying to remove time and change date format?

How to fixed error "discord.ext.commands.errors.MissingRequiredArgument: member is a required argument that is missing."