Converting Date Time values

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Converting Date Time values

reichmaj
r-help

 

Generally speaking is it better to convert date/time values to "POSIXlt" and
"POSIXct" objects?

 

Jeff Reichman

 


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Converting Date Time values

Bert Gunter-2
Did you mean to use "or" instead of "and" in your query?

If so, no comment. If "and," then yes, as that allows a great deal of
functionality (ordering, comparisons, time-date arithmetic, etc.) that
would otherwise be painful or require special packages. IMO only, of course.


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Apr 26, 2021 at 11:26 AM Jeff Reichman <[hidden email]>
wrote:

> r-help
>
>
>
> Generally speaking is it better to convert date/time values to "POSIXlt"
> and
> "POSIXct" objects?
>
>
>
> Jeff Reichman
>
>
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Converting Date Time values

reichmaj
Whoops happy fingers yes I meant “or”

 

From: Bert Gunter <[hidden email]>
Sent: Monday, April 26, 2021 1:37 PM
To: [hidden email]
Cc: R-help <[hidden email]>
Subject: Re: [R] Converting Date Time values

 

Did you mean to use "or" instead of "and" in your query?

 

If so, no comment. If "and," then yes, as that allows a great deal of functionality (ordering, comparisons, time-date arithmetic, etc.) that would otherwise be painful or require special packages. IMO only, of course.

 




Bert Gunter

"The trouble with having an open mind is that people keep coming along and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

 

 

On Mon, Apr 26, 2021 at 11:26 AM Jeff Reichman <[hidden email] <mailto:[hidden email]> > wrote:

r-help



Generally speaking is it better to convert date/time values to "POSIXlt" and
"POSIXct" objects?



Jeff Reichman




        [[alternative HTML version deleted]]

______________________________________________
[hidden email] <mailto:[hidden email]>  mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: [EXT] Converting Date Time values

dkStevens
In reply to this post by reichmaj
I use both routinely, depending on the need. 'ct' is great for
representing date/time holistically (2021-04-26 13:21:27) and is numeric
under the hood in seconds since the big bang (just kidding), kind of
like julian seconds. 'lt' is a list of 7 elements that often require
manipulation (e.g. lt$mon = month of the year starting with Jan = 0) but
it's great for extracting values like day of the year, day of the week,
etc. w/o having to do it yourself - saves a heap of error-fraught
coding. One draw back is the handling of daylight savings shifts. In
March, an hour gets lost (jumps from 0159 to 0300) and in October you
get an hour twice, so if you're using code that requires 1 hour steps,
you get hiccups twice/year, so that requires special handling. Don't
overlook 'strptime' to convert non-standard dates (e.g. '4/26/21' isn't
recognized by as.POSIXct but strptime can do the conversions for you.)

David Stevens

On 4/26/2021 12:26 PM, Jeff Reichman wrote:

> r-help
>
>
>
> Generally speaking is it better to convert date/time values to "POSIXlt" and
> "POSIXct" objects?
>
>
>
> Jeff Reichman
>
>
>
>
>          [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> CAUTION: This email originated from outside of USU. If this appears to be a USU employee, beware of impersonators. Do not click links, reply, download images, or open attachments unless you verify the sender’s identity and know the content is safe.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Converting Date Time values

Duncan Murdoch-2
In reply to this post by reichmaj
On 26/04/2021 3:08 p.m., Jeff Reichman wrote:
> Whoops happy fingers yes I meant “or”
>

POSIXct are easier to work with as data (e.g. a column in a dataframe).
  POSIXlt is easier to work with as dates & times, and has a bigger range.

See details of the comparison in the ?POSIXt help page.

Duncan Murdoch

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.