Questions tagged [string-to-datetime]
217 questions
216
votes
17 answers
Sql Server string to date conversion
I want to convert a string like this:
'10/15/2008 10:06:32 PM'
into the equivalent DATETIME value in Sql Server.
In Oracle, I would say this:
TO_DATE('10/15/2008 10:06:32 PM','MM/DD/YYYY HH:MI:SS AM')
This question implies that I must parse the…

JosephStyons
- 57,317
- 63
- 160
- 234
59
votes
3 answers
Why is pandas.to_datetime slow for non standard time format such as '2014/12/31'
I have a .csv file in such format
timestmp, p
2014/12/31 00:31:01:9200, 0.7
2014/12/31 00:31:12:1700, 1.9
...
and when read via pd.read_csv and convert the time str to datetime using pd.to_datetime, the performance drops dramatically. Here is a…

liubenyuan
- 733
- 1
- 5
- 10
23
votes
1 answer
How to convert numpy.timedelta64 to minutes
I have a date time column in a Pandas DataFrame and I'd like to convert it to minutes or seconds.
For example: I want to convert 00:27:00 to 27 mins.
example = data['duration'][0]
example
result: numpy.timedelta64(1620000000000,'ns')
What's the…

Behzad Shahbaz
- 235
- 1
- 2
- 5
17
votes
4 answers
NSDateFormatter return wrong date + Swift
Code :
let dateString = "2016-04-02"
var formatter: NSDateFormatter = NSDateFormatter()
formatter.timeZone = NSTimeZone(abbreviation: "GMT +3:00")
formatter.dateFormat = "yyyy-MM-dd"
println("dateString: \(dateString)")
…

Sanjay Kumar
- 415
- 4
- 9
- 19
10
votes
3 answers
Converting a unix time stamp to twitter/facebook style
I'm trying to convert a unix time stamp to display like facebook and twitter. For example, when you see tweets or comments placed on twitter/facebook you see the date/time displayed like so:
'2 mins ago' or '2 days ago' or '2 weeks ago'
Does anyone…

HomeBrew
- 849
- 2
- 12
- 25
8
votes
1 answer
How to fix ParserError: year 0 is out of range: 0000-00-00 with Python Pandas to_datetime method
I am trying to convert a column "travel_start" to a datetime object.
Dashboard["travel_start"] = pd.to_datetime(Dashboard["travel_start"])
But I get the following error:
ParserError: year 0 is out of range: 0000-00-00
When I tried to filter the…

JA-pythonista
- 1,225
- 1
- 21
- 44
8
votes
2 answers
Change dataframe column names from string format to datetime
I have a dataframe where the names of the columns are dates (Year-month) in the form of strings. How can I convert these names in datetime format?
I tried doing this:
new_cols = pd.to_datetime(df.columns)
df = df[new_cols]
but I get the…

gtroupis
- 161
- 1
- 4
- 13
8
votes
3 answers
How do I cast dd/mm/yyyy string into date in BigQuery?
I have 3 columns
1. dd/mm/yyyy (stored as a string)
2. app_id and #downloads of apps
I have to find unique ids of apps downloaded within a week.
Thank you

Saurabh Kumar
- 137
- 1
- 1
- 8
8
votes
2 answers
Using strptime %z with special timezone format
I am working with .csv data that was exported from Teradata. Several columns were originally timestamps with timezones, so after loading the .csv in R I'd like to convert these columns (which are loaded as strings) to POSIXlt or POSIXct. I am…

dnlbrky
- 9,396
- 2
- 51
- 64
6
votes
6 answers
str_to_date function in sql server?
MySQL has a function called STR_TO_DATE, that converts a string to date.
Question:
Is there a similar function in SQL Server?

Alex Gordon
- 57,446
- 287
- 670
- 1,062
5
votes
2 answers
Pandas Converting date string (only month and year) to datetime
I am trying to convert a datetime object to datetime. In the original dataframe the data type is a string and the dataset has shape = (28000000, 26). Importantly, the format of the date is MMYYYY only. Here's a data sample:
…

Simone Di Claudio
- 131
- 1
- 2
- 8
4
votes
1 answer
Slow pd.to_datetime()
I am reading two types of csv files that are very similar.
They are about the same lenght, 20 000 lines. Each line represent parameters recorded each second.
Thus, the first column is the timestamp.
In the first file, the pattern is the following:…

Maxime
- 594
- 5
- 17
4
votes
1 answer
Convert String With Milliseconds To Date Format In Java
I am trying to convert a string with milliseconds (20180510-10:50:58.106) to date in java. However, when I convert it I get the millisecond part but again in the string. I want the same part in date format.
import java.text.ParseException;
import…

chetan
- 1,385
- 4
- 15
- 31
4
votes
1 answer
Python change the date format from dd/mm/yy to dd/mm/yyyy for the dates before 1970
I have a python pandas data frame that has a date column like below:
'Birth Date'
0 22/04/73
1 22/03/53
2 22/04/73
3 14/08/77
4 08/05/50
I want to convert this object datatype to date format, something like this: 04/06/1953...
I…

Nithin Das
- 364
- 1
- 5
- 14
4
votes
3 answers
In python pandas, how can I convert this formatted date string to datetime
I have tried several ways of using to_datetime, but so far I can only get it to return the dtype as "object"
pd.to_datetime(pd.Series(['28Dec2013 19:23:15']),dayfirst=True)
The return from this command is:
0 28Dec2013 19:23:15
dtype: object

claudiaann1
- 237
- 3
- 12