Concatenate Dates with leading zeroes

caj1980

Board Regular
Joined
Oct 23, 2013
Messages
108
I need to take a date format from a database dump and Concatenate it into a new cell to format it the way I need so I can perform calculations. I have the calculations working but I need to figure out how to insert leading zeroes for single-digit months and years so that all dates end up with the same number of characters (YYYYMMDD, not YYYYMD). I have played with custom formatting the cells using ## but can't seem to get it to work with concatenate. Row1 is column headers, Row2 is formulas, Row3 is desired results. Any help would be greatly appreciated!
Any help would be greatly appreciated!ABCDE
1Submit DateClosed DateCONC SubmitCONC ClosedDuration
25/1/2014 2:03:08 AM5/9/2014 4:34:24 PM=CONCATENATE(YEAR(A2),MONTH(A2),DAY(A2))=CONCATENATE(YEAR(B2),MONTH(B2),DAY(B2))=D2-C2
3 20140501201405098

<tbody>
</tbody>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Concatenate or Text treats date as string
In D2 Try,

=DATE(YEAR(B2),MONTH(B2),DAY(B2))

Then right click format cells as YYYYMMDD
 
Last edited:
Upvote 0
did ou try to use TEXT function?


Excel 2010
ABCD
1Submit DateClosed Date
205/01/2014 02:0305/09/2014 16:342014010520140905
Sheet4
Cell Formulas
RangeFormula
C2=TEXT(A2,"yyyymmdd")
D2=TEXT(B2,"yyyymmdd")
 
Upvote 0
Try

=TEXT(A2,"yyyymmdd")

However, it's not really a date anymore, just a number 20140501 (stored as a text string)

Your subtraction in E will not be accurate when the dates span 2 or more months.
i.e. Jun 9 - May 9
20140609 - 20140509 = 100, not 31


Dates are numbers by themselves, you can just do B2-A2
But since the dates in A and B contain time as well, try
=INT(B2)-INT(A2)


Hope that helps.
 
Upvote 0
Hi,

If A2 & B2 are recognised by Excel as Dates then you should not need to format i.e. =B2-A2 should give you the difference 8.605. if you need the time part stripped out you can use =INT(B2-A2)

Alternatively if the format is just for display then =Text(A2,"yyyymmdd") will give you 20140501.

Hope this helps,

Eric.
 
Upvote 0
Try=TEXT(A2,"yyyymmdd")However, it's not really a date anymore, just a number 20140501 (stored as a text string)Your subtraction in E will not be accurate when the dates span 2 or more months.i.e. Jun 9 - May 920140609 - 20140509 = 100, not 31Dates are numbers by themselves, you can just do B2-A2But since the dates in A and B contain time as well, try=INT(B2)-INT(A2)Hope that helps.
This worked beautifully!!! Thank you!!!
 
Upvote 0

Forum statistics

Threads
1,216,155
Messages
6,129,185
Members
449,492
Latest member
steveg127

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top