http://qs321.pair.com?node_id=1179202


in reply to Re: Finding the difference between two dates including milliseconds
in thread Finding the difference between two dates including milliseconds

Looks like the DateTime object accepts the input as the below format and not the data I have
"Mon Mar 27 05:54:08 CDT 2009";
  • Comment on Re^2: Finding the difference between two dates including milliseconds
  • Download Code

Replies are listed 'Best First'.
Re^3: Finding the difference between two dates including milliseconds (updated)
by haukex (Archbishop) on Jan 09, 2017 at 06:33 UTC

    Hi Anonymous,

    AFAIK DateTime doesn't accept strings at all; I'm not sure where you're getting that specific format from? Again, please show the code you are trying, along with some sample input, the expected output for that sample input, and the actual output of the code including exact error messages, if any - see How do I post a question effectively?

    DateTime::Format::Strptime will accept the data in almost any format including the one in the OP, but you'll have to build an appropriate pattern according to its documentation. So something like "%Y-%m-%d ..." - scroll down in the documentation to see all the different tokens and pick the ones appropriate for your format.

    Update: Hint: Super search is your friend, among the first search results you'll find example code posted by myself and others.

    Update 2: Hm, I'm guessing you may have gotten the string "Mon Mar 27 05:54:08 CDT 2009" from this StackOverflow post. Note that that code uses Time::ParseDate, and not DateTime. Follow the links I've given you and you'll find the appropriate documentation including example code.

    Regards,
    -- Hauke D