ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   formatting date (https://www.excelbanter.com/excel-programming/285105-formatting-date.html)

inquirer

formatting date
 
I have the following code:

dd = Right(sd, 2)
mm = Mid(sd, 3, 2)
yy = Left(sd, 2)
temp = dd & "/" & mm & "/20" & yy
temp = Format(temp, "dd/mm/yy")
Cells(3, "c").Value = temp

where sd is s string which contains a date in the format 031124.

I want the value to appear in cells(3,"c") in the format 24/11/03.

No matter what I do, the format always ends up as 11/24/2003.

Is there a way of making excel do what I want, not what it wants?
Thanks
Chris



raymondsum[_12_]

formatting date
 
Chris,

I dont take consideration of your code, just input formula i
worksheet.

you may try this,

Cell A1=031124
Cell A3=Date(Left(A1,2),Mid(A1,3,2),Right(A1,2))=24/11/03

HTH

Raymon

--
Message posted from http://www.ExcelForum.com


Ron Rosenfeld

formatting date
 
On Thu, 11 Dec 2003 16:01:29 +1100, "inquirer" wrote:

I have the following code:

dd = Right(sd, 2)
mm = Mid(sd, 3, 2)
yy = Left(sd, 2)
temp = dd & "/" & mm & "/20" & yy
temp = Format(temp, "dd/mm/yy")
Cells(3, "c").Value = temp

where sd is s string which contains a date in the format 031124.

I want the value to appear in cells(3,"c") in the format 24/11/03.

No matter what I do, the format always ends up as 11/24/2003.

Is there a way of making excel do what I want, not what it wants?
Thanks
Chris


This seems to work for me:

=======================
Sub DtTest()
Const sd As String = "031124"
Dim dd As Integer, mm As Integer, yy As Integer
Dim temp As Date

dd = Right(sd, 2)
mm = Mid(sd, 3, 2)
yy = Left(sd, 2)

temp = DateSerial(yy, mm, dd)

Cells(3, "c").Value = temp
Cells(3, "c").NumberFormat = "dd/mm/yy"

End Sub
========================


--ron


All times are GMT +1. The time now is 12:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com