Page 1
Page 1
Started By
Message

Need excel help - automate text to date time format

Posted on 6/1/23 at 10:00 am
Posted by castorinho
13623 posts
Member since Nov 2010
82044 posts
Posted on 6/1/23 at 10:00 am
I have a dataset with a column that displays date time in text in the following format:

Thu Jun 1 2023 09:49:47 GMT-0500 (central Daylight time)

The goal is to have another column that will calculate NOW minus the above colum, with the result in days. And more importantly I want to have that automated.

I can trim the original text to look like a date with LEFT and RIGHT, but having issues with excel picking up that date formatting.

Posted by whiskey over ice
Member since Sep 2020
3270 posts
Posted on 6/1/23 at 11:27 am to
have you tried DATEFORMAT?
Posted by VADawg
Wherever
Member since Nov 2011
44923 posts
Posted on 6/1/23 at 12:14 pm to
quote:

Thu Jun 1 2023 09:49:47 GMT-0500 (central Daylight time)


Let's assume this is in cell A1. Type =NOW()-A1 in whatever cell you want the result to appear in. Format that cell to general.

If I understand you correctly, this should get you the answer you're looking for.
Posted by mdomingue
Lafayette, LA
Member since Nov 2010
30403 posts
Posted on 6/1/23 at 12:58 pm to
There is an issue with your format for the dataset. You need a comma.

Thu Jun 1, 2023 09:49:47 for instance

Then you can use this to get what you want

=DAYS(NOW(),RIGHT(LEFT(A1,FIND(":",A1)-4),LEN(LEFT(A1,FIND(":",A1)-4))-FIND(" ",LEFT(A1,FIND(":",A1)-4))))

If you cannot easily add the comma, I can get add something to do that as well.
Posted by castorinho
13623 posts
Member since Nov 2010
82044 posts
Posted on 6/1/23 at 1:56 pm to
OK let me try that
Posted by Brisketeer
Texas
Member since Aug 2013
1437 posts
Posted on 6/1/23 at 2:17 pm to
This is assuming K1 has the date/time string.

=DATEDIF(DATEVALUE(INDEX(TEXTSPLIT(K1," "),2) & " " & INDEX(TEXTSPLIT(K1," "),3) & ", " & INDEX(TEXTSPLIT(K1," "),4)) +TIMEVALUE(INDEX(TEXTSPLIT(K1," "),5)),NOW(),"yd")
Posted by castorinho
13623 posts
Member since Nov 2010
82044 posts
Posted on 6/1/23 at 2:25 pm to
Used LEFT(A1, 10)&","RIGHT(LEFT(S2) - 33), 14) To insert the comma. Then I applied your formula to that worked perfectly!
Thank you.

Posted by mdomingue
Lafayette, LA
Member since Nov 2010
30403 posts
Posted on 6/1/23 at 2:32 pm to
Greet, glad to help
Posted by Chromdome35
NW Arkansas
Member since Nov 2010
6846 posts
Posted on 6/1/23 at 2:46 pm to
This is a perfect use case for asking chatGPT how to do something. I use it for crafting advanced Excel formulas all the time.

From ChatGPT
quote:

In Excel, I have a dataset with a column that displays date time in text in the following format:

Thu Jun 1 2023 09:49:47 GMT-0500 (central Daylight time)

The goal is to have another column that will calculate NOW minus the above colum, with the result in days. And more importantly I want to have that automated.

ChatGPT Response
To calculate the difference between the current date and the dates in your dataset in Excel, you can use the following steps:

Assuming your dataset starts from cell A2, enter the following formula in cell B2:

excel
Copy code
=DATEDIF(DATEVALUE(MID(A2,FIND(" ",A2)+1,3)&" "&MID(A2,FIND(" ",A2)+5,1)&" "&MID(A2,FIND(" ",A2)+6,4)),TODAY(),"d")
Drag the formula down to apply it to the remaining cells in column B.

This formula works by extracting the relevant parts from the date text using the MID and FIND functions. It then converts the extracted text into a valid date format using DATEVALUE. Finally, it calculates the difference between the converted date and the current date using the DATEDIF function, specifying "d" as the unit to get the result in days.

As you requested automation, the formula uses the TODAY() function, which will always give you the current date. Therefore, whenever you open the Excel file or recalculate the sheet, the formula will update automatically to reflect the current date.
This post was edited on 6/1/23 at 2:47 pm
Posted by Chromdome35
NW Arkansas
Member since Nov 2010
6846 posts
Posted on 6/1/23 at 2:52 pm to
Asking it for a second option:

quote:

Is there a different option to use?

ChatGPT Response

Certainly! An alternative option to calculate the difference in days between the current date and the dates in your dataset is by using the DAYS function in combination with the DATEVALUE and LEFT functions. Here's how you can do it:

Assuming your dataset starts from cell A2, enter the following formula in cell B2:

excel
Copy code
=DAYS(TODAY(), DATEVALUE(LEFT(A2, 15)))
Drag the formula down to apply it to the remaining cells in column B.

In this formula, the LEFT function is used to extract the first 15 characters from the date text, which represent the date in the format "Thu Jun 1 2023". The DATEVALUE function is then used to convert the extracted date text into a valid date format.

The DAYS function calculates the difference in days between the current date (obtained using TODAY()) and the converted date value, giving you the desired result.

Just like the previous solution, this formula will update automatically whenever you open the Excel file or recalculate the sheet.
first pageprev pagePage 1 of 1Next pagelast page
refresh

Back to top
logoFollow TigerDroppings for LSU Football News
Follow us on Twitter, Facebook and Instagram to get the latest updates on LSU Football and Recruiting.

FacebookTwitterInstagram