0

I have an input which may contain a date, or time, or both. In case the date is provided I can use that date but in case the date is not provided (i.e. only the time is provided) then I have to use a different date provided from someplace else.

But once I parse the date using using python dateutil, today's date is added to the parsed value. For example:

from dateutil.parser import parse
print(parse('03:15:08'))
print(parse('04-04-2019 03:15:08'))

the above code gives the following output:

2019-04-04 03:15:08
2019-04-04 03:15:08

As you can see the information (that the date was provided or not) is lost and can't be differentiated.

Also some kind of length manipulation may not work because only the date may be provided.

How to differentiate between the 2 inputs?

Thank you.

guroosh
  • 642
  • 6
  • 18
  • id suggest checking for a colon in the original string, and a date separator such as slash/hyphen. depending on the presence or absence of those, you could then keep only the date/time/both portion of the parsed return – Zulfiqaar Apr 04 '19 at 11:23
  • Could you provide a sample of your input string? That is normal behavior of `parser` though. – DirtyBit Apr 04 '19 at 11:25
  • @DirtyBit the above 2 strings in the question are the inputs. – guroosh Apr 04 '19 at 12:13

0 Answers0