Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Date format text conversion
I am trying to convert the current date in to a four digit date ex:
Jan 3 = 0103 Jan 4 = 0104 etc What I get instead is 103 or 104 etc. If i go to another cell and use =text(cell,"mmdd") I get the desired result or format the cell for text. Unfortunately those are not options. Perhaps it's my approach. Here is what I am using in my attempts: Dim sdte As Date Dim dv As String sdte = Date Range("D2").Value = Format(sdte, "mmdd") Range("e2").Value = sdte dv = DateValue(sdte) Range("f3").Value = dv Range("e4").Value = Format(dv, "mmdd") Range("E6").Value = CDate(dv) I have also tried Now() I have also tried "mmmdd" and "0000" in the formats these give me results of a different date because of the datevalue / system date (39450) any help is greatly appreciated. Thanks |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Date format text conversion
Use
[D2].NumberFormat = "@" [D2]=format(date,"mmyy") Otherwise it is like typing 0103 in a cell: it is still interpreted as a number, unless you formatted it as text before. -- Kind regards, Niek Otten Microsoft MVP - Excel "Dan" wrote in message ... |I am trying to convert the current date in to a four digit date ex: | Jan 3 = 0103 | Jan 4 = 0104 etc | | What I get instead is 103 or 104 etc. If i go to another cell and use | =text(cell,"mmdd") I get the desired result or format the cell for text. | Unfortunately those are not options. Perhaps it's my approach. Here is what I | am using in my attempts: | | Dim sdte As Date | Dim dv As String | sdte = Date | Range("D2").Value = Format(sdte, "mmdd") | Range("e2").Value = sdte | | dv = DateValue(sdte) | Range("f3").Value = dv | Range("e4").Value = Format(dv, "mmdd") | Range("E6").Value = CDate(dv) | | I have also tried Now() | | I have also tried "mmmdd" and "0000" in the formats these give me results of | a different date because of the datevalue / system date (39450) any help is | greatly appreciated. Thanks |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
permanent conversion of 1904 date format to 1900 date format | Excel Worksheet Functions | |||
TEXT DATE Format Conversion | Excel Programming | |||
Conversion of date into different format | Excel Discussion (Misc queries) | |||
Date format conversion | Excel Discussion (Misc queries) | |||
Date Format - Conversion | Excel Discussion (Misc queries) |