FAQ Database Discussion Community


How to convert variable to time format when values have different formatting

r,format,strptime,chron
I am trying to convert a variable that contains that length of time of a phone call from a factor into a chronological format using the chron function. However, the values for calls that were less then 1 hour are reported as m:s, while calls that were longer then an...

strptime returning NA values [closed]

r,date,format,na,strptime
I'm trying to use strptime to format dates I'm reading in but only get NA values are returned in the output. My raw data is in the format of 1974-01-01, and the length of the dataset is 12049 so the last date is 2006-12-31. The code I use is: Data$date.yyyymmdd...

R help converting char to POSIXlt

r,datetime,time,strptime,posixlt
I am having a lot of problems converting a char data.frame into a POSIXlt. This is my str output: 'data.frame': 5846 obs. of 5 variables: $ date : Factor w/ 184 levels "1/1/2015","1/10/2015",..: 31 31 31 31 31 31 31 31 31 31 ... $ time : Factor w/ 680...

Python custom datetime(?) format handling

python,date,datetime,time,strptime
Let's say i have a string representing a time with number of day of the week: For example '52300', which means 5th day of week(Friday), 23 Hours 00 Minutes. How do i parse it to time or datetime object to add a timedelta(hours=3) and get it back to this strange...

strange encoding issue with strptime

python,encoding,strptime
I need to convert 14 Şubat 2015 Cumartesi, 09:47:49 to datetime. when I print this date it works fine but I couldn't change the encoding inside of time.strptime no matter what I try encoding or decoding to different type. here is my code # -*- coding: cp1254 -*- import chardet...

Parsing date using strftime

ruby-on-rails,ruby,strptime
I have a problem parsing dates taken in from scraping a website using Nokogiri. I scrape the datetime using @date = h4.at('time[itemprop="startDate"]')[:datetime] This gives me 2015-04-28 19:30:00 UTC, which is inserted into my date column, of type "datetime". Using strptime I am trying to parse the date into a "dd/mm"...

How to convert string with UTC offset

python,datetime,strptime
I have date as In [1]: a = "Sun 10 May 2015 13:34:36 -0700" When I try to convert it using strptime, its giving error. In [3]: datetime.strptime(a, "%a %d %b %Y %H:%M:%S %Z" ...: ) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-3-973ef1c6daca> in <module>() ----> 1 datetime.strptime(a, "%a...

Converting date and time from String format to Python datetime object: ValueError: time data '… p.m.' does not match format '… %p'

python,datetime,strptime
I have date and time in the below String format: dateTime = '21-03-2015 12:20 p.m.' And I want to convert it into Python datetime object. I'm doing something like below: dateTimeObj = datetime.datetime.strptime(dateTime, '%d-%m-%Y %I:%M %p') But I keep getting the below error: ValueError: time data '21-03-2015 12:20 p.m.' does...

C++ strptime giving wrong results

c++,time,strptime
I'm parsing a file containing strings formatted as DD/MM/YYYY HH:MM:SS. I'm trying to read them and convert them to Unix timestamps, using the following code : tm tm; cout << datestr << endl; strptime(str.c_str(), "&d/&m/&Y %H:&M:&S", &tm); cout << tm.tm_year << " " << tm.tm_mon << " " << tm.tm_mday...

Python datetime.strptime - Converting month in String format to Digit

python,datetime,strptime
I have a string that contains the date in this format: full_date = "May.02.1982" I want to use datetime.strptime() to display the date in all digits like: "1982-05-02" Here's what I tried: full_date1 = datetime.strptime(full_date, "%Y-%m-%d") When I try to print this, I get garbage values like built-in-67732 Where am...