View Full Version : Change Date format after user imput
dariojalon
12-07-2012, 06:53 AM
Hi to all. I have a quick question I hope you could answer.
I have a form were a user imputs a date in the following format: dd/mm/yyyy
The thing is that later on I need that date with the following format: Ej.: "1 of May of 2012"
The code I wrote for the user imput goes as follows:
Set oVars = ActiveDocument.Variables
oVars("Date").Value = Me.TextBox29.Value
'this is the date as dd/mm/yyyy
¿¿How could I define the oVars with a differente date format??
Thanks a lot. Best regards.
fumei
12-07-2012, 12:44 PM
Look up Format in Help. The problem is that Format does not have the "of " as a choice. However, the output of Format is a string, so you can break it up.ActiveDocument.Variables("Date").Value = "22/10/1953"
Msgbox Format(ActiveDocument.Variables("Date").Value, "dd mmmm yyyy")Returns:
22 October 1953
MsgBox Format(ActiveDocument.Variables("Date").Value, "dd ") & _
"of " & Format(ActiveDocument.Variables("Date").Value, "mmmm ") & _
"of " & Format(ActiveDocument.Variables("Date").Value, "yyyy")
Returns:
22 of October of 1953
The code concatenates the day part ("dd"), the string "of ", the month part ("mmmm"), the string "of ", and finally the year part ("yyyy"). Note the addition of spaces between the words - "dd ", and "mmmm ".
Note that the code returns "day of month of year" regardless of what is the actual variable value, because you are applying Format to the value when you use the value. If you want to change the variable value itself:
ActiveDocument.Variables("Date").Value = _
Format(ActiveDocument.Variables("Date").Value, "dd ") & _
"of " & Format(ActiveDocument.Variables("Date").Value, "mmmm ") & _
"of " & Format(ActiveDocument.Variables("Date").Value, "yyyy")Now the variable value is the string "day of month of year"
dariojalon
12-07-2012, 01:50 PM
It worked great!! THANKS!!
macropod
12-09-2012, 01:15 AM
Hint:
Format(ActiveDocument.Variables("Date").Value, "dd" & " of " & "mmmm" & " of " & "yyyy")
fumei
12-09-2012, 04:02 AM
Damn. Of course you are correct, it IS - after all - one string. Doh. I need a vacation.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.