4

all,

I am using R on the Azure machine learning, and I have some problems.

I want to use program R to calculate the difference between two date, for example, 2014/11/01 and 2014/11/03.

I using the function "strptime" in R to do this thing, it can work on my own computer, but when I want to run the same code on Azure ml, it came out the error.

The error is :

[ModuleOutput] 1: In strptime(x, format, tz = tz) :
[ModuleOutput] 
[ModuleOutput]   unable to identify current timezone 'C':
[ModuleOutput] 
[ModuleOutput] please set environment variable 'TZ'
[ModuleOutput] 
[ModuleOutput] 2: In strptime(x, format, tz = tz) : unknown timezone 'localtime'

I think the problem is that it can't detect the timezone on Azure ml, but I'm not sure.

Is there any way to solve this problem?

Thanks in advance.

KST
  • 589
  • 9
  • 15
  • Which timezones does the system support? What is the value of `tz`? – Roland Nov 06 '14 at 08:33
  • Hi, thanks for your reply. I am not sure which timezone that azure will support, because I only need to calculate the difference between two date. I finally found the problem what I encounter, it is about the azure will detect the csv automatically, and regarded the date string as the date form. So I can't use the original R code to show the same output. – KST Nov 12 '14 at 03:16

1 Answers1

0

I think you are encountering a similar issue like this post: How to define current time zone in Azure ML for strptime function, unknown timezone 'localtime'

One possible solution is to use Sys.setenv(TZ=‘UTC’) before calling strptime.

To calculate the difference between two dates with R language on Azure Machine Learning, you can use the difftime function. This function takes two date-time objects as arguments and returns the difference in seconds by default. You can specify other units such as days or weeks with the units argument.

For example, if you want to calculate the difference between 2014/11/01 and 2014/11/03 in days, you can use this code:

# Convert strings to date-time objects
date1 <- as.POSIXct("2014/11/01", format = "%Y/%m/%d")
date2 <- as.POSIXct("2014/11/03", format = "%Y/%m/%d")

# Calculate the difference in days
difftime(date2, date1, units = "days")

This will return 2 days as the result.

TechWizard
  • 346
  • 1
  • 7