Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,440
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
permanent conversion of 1904 date format to 1900 date format Jos Excel Worksheet Functions 4 November 26th 15 02:48 PM
TEXT DATE Format Conversion Ashish_Vaidya Excel Programming 1 February 13th 07 10:52 PM
Conversion of date into different format Fam via OfficeKB.com Excel Discussion (Misc queries) 8 July 31st 06 09:14 PM
Date format conversion Terry Pinnell Excel Discussion (Misc queries) 5 November 21st 05 07:53 PM
Date Format - Conversion tinkertoy Excel Discussion (Misc queries) 1 July 14th 05 06:24 PM


All times are GMT +1. The time now is 03:09 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"