PDA

View Full Version : Want to convert a Date



amit_nalawad
06-06-2008, 03:05 AM
Hi,

I have a date format 5/29/2008. I want to convert it to 29-May-2008 using VB script. This is not related to excel.

Please help me for this. that will be very Appreciated



Thanks
Amit

marshybid
06-06-2008, 03:15 AM
Hi,

Are you trying to convert the format for a range of cells?

I use a number of date conversion methode depending on what I need to accomplish and the layout of the data.

If all of your dates are in column C for example you could try



Columns("C:C").Select
Selection.NumberFormat = "dd-mmm-yyyy"


Hope this helps

Marshybid

amit_nalawad
06-06-2008, 03:21 AM
Actually I am not talking about excel date format. I want a genral VB code which will convert given date to dd-mm-yy format.

JimmyTheHand
06-06-2008, 03:24 AM
Dim D as Date
MsgBox Format(D, "dd-mmmm-yyyy")

if you want full month name, or
Dim D as Date
MsgBox Format(D, "dd-mmm-yyyy")

if you want 3 character abbreviations.

Jimmy

marshybid
06-06-2008, 03:31 AM
Oops, I missed the clear clue in the original question!!!!!:rotlaugh:



This is not related to excel.


Marshybid :hi:

amit_nalawad
06-06-2008, 03:49 AM
Hi Jimmy,

That is nice solution. But do you another solutions in same manner

JimmyTheHand
06-06-2008, 03:52 AM
Hi Jimmy,

That is nice solution. But do you another solutions in same manner
:wot Excuse me?

marshybid
06-06-2008, 04:06 AM
Hi jimmy,

I'm not sure what amit wants?? I misread his original query, but I thought your answer was great.

BTW, How do you include the 'Originally Posted by' info in your quote??

On another note, for formatting dates across a spreadsheet, how would I use the ISDATE () function to review all cells (I can write the code to loop through all rows) then where a date is found, format to desired output??

Thanks

Marshybid :think:

Bob Phillips
06-06-2008, 04:23 AM
BTW, How do you include the 'Originally Posted by' info in your quote??

There is a big Quote button in the previous response, hit that instaed of reply.


On another note, for formatting dates across a spreadsheet, how would I use the ISDATE () function to review all cells (I can write the code to loop through all rows) then where a date is found, format to desired output??

When you get the cell, then use


With cell

If IsDate(cell.Value) Then

cell.NumberFormat = "dd mmm yyyy"
End If
End With

marshybid
06-06-2008, 04:39 AM
With cell

If IsDate(cell.Value) Then

cell.NumberFormat = "dd mmm yyyy"
End If
End With


Thanks xld, once again you make it all so clear.

Marshybid