Quantcast

date and time conversion

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

date and time conversion

mpostje
Hi

I've been trying to convert numbers from an online temperature database
into dates and time that R recognizes. the problem is that the database has put a T
between the numbers and R will not accept any conversions.

this is the format that it's in now
1981-01-02T08:00

can anyone help?
cheers!     
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: date and time conversion

Michael Weylandt
Quick and dirty solution is to use sub() to change the T to a space
and then use as.POSIXct as usual.

x <- "1981-01-02T08:00"

as.POSIXct(sub("T"," ", x), format = "%Y-%m-%d %H:%M")

but it does look to me like R can work around the T if you give a good
format argument:

as.POSIXct(x, format = "%Y-%m-%dT%H:%M")

Michael

On Wed, May 2, 2012 at 6:10 AM, mpostje <[hidden email]> wrote:

>
>
>
>
> Hi
>
> I've been trying to convert numbers from an online temperature database
> into dates and time that R recognizes. the problem is that the database has put a T
> between the numbers and R will not accept any conversions.
>
> this is the format that it's in now
> 1981-01-02T08:00
>
> can anyone help?
> cheers!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/date-and-time-conversion-tp4602786.html
> Sent from the R help mailing list archive at Nabble.com.
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.

______________________________________________
[hidden email] mailing list
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
|  
Report Content as Inappropriate
star

Re: date and time conversion

Rui Barradas
In reply to this post by mpostje
Hello,

mpostje wrote
Hi

I've been trying to convert numbers from an online temperature database
into dates and time that R recognizes. the problem is that the database has put a T
between the numbers and R will not accept any conversions.

this is the format that it's in now
1981-01-02T08:00

can anyone help?
cheers!
Try

x <- "1981-01-02T08:00"
x.new <- sub("T", " ", x)
as.POSIXct(x.new)

Hope this helps,

Rui Barradas
Loading...