PC Review


Reply
Thread Tools Rate Thread

Date format text conversion

 
 
Dan
Guest
Posts: n/a
 
      3rd Jan 2008
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 With Quote
 
 
 
 
Niek Otten
Guest
Posts: n/a
 
      3rd Jan 2008
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" <(E-Mail Removed)> wrote in message news:ACC98970-231D-470E-AFE4-(E-Mail Removed)...
|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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
permanent conversion of 1904 date format to 1900 date format Jos Microsoft Excel Worksheet Functions 3 21st Jul 2009 06:32 PM
date format conversion buckpeace Microsoft Access Queries 1 19th Dec 2007 04:18 PM
Date format conversion chris Microsoft Access Forms 8 11th May 2007 07:57 PM
TEXT DATE Format Conversion =?Utf-8?B?QXNoaXNoX1ZhaWR5YQ==?= Microsoft Excel Programming 1 13th Feb 2007 10:52 PM
Date Format Conversion Mario Microsoft Access Queries 7 8th Jul 2004 02:41 AM


Features
 

Advertising
 

Newsgroups
 


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