|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Greetings all -
I have a date format issue that I'm having trouble resolving. Currently I have a process that displays a date in the following format : January 2,2004 Looks gr8 but it needs to be in this format: January 2nd,2004 I'm using format(myDate, "mmmm d, yyyy") and in Oracle to get the date displayed properly the command is something like : to_char(myDate, 'fmMonthfm fmddthfm, yyyy') Does anyone know how to accomplish this in VB? Any help would be appreicated. |
|
#2
|
||||
|
||||
|
if you can convert it to a string then this would not be difficult, I'm not sure of a way to do this in a date/time variable, however. Does it need to remain a date variable?
|
|
#3
|
|||
|
|||
|
VB Date format
Thanks for the repsonse Fisherman.
No, this is for display purposes only so it's a string. |
|
#4
|
||||
|
||||
|
if it's just a string, declare a string variable and use the instr() and Mid() functions to break your date apart, add in the "nd", and reassemble it... maybe something like this...
Code:
dim strDate as string strDate = mid(0,instr(cstr(myDate),",")-1) & "nd" & mid(instr(mydate,","),len(cstr(mydate)) upon further reflection, this is not the best way to do it, since not every date ends with "nd"... I'll look some more.
__________________
Fisherman "Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction." - A.Einstein |
|
#5
|
|||
|
|||
|
This might work wrapped in a select case:
Select case myDate case 1,21,31 myDate = mid(0,instr(cstr(myDate),",")-1) & "st" & mid(instr(mydate,","),len(cstr(mydate)) case 2,22 myDate = mid(0,instr(cstr(myDate),",")-1) & "nd" & mid(instr(mydate,","),len(cstr(mydate)) case 3,23 myDate = mid(0,instr(cstr(myDate),",")-1) & "rd" & mid(instr(mydate,","),len(cstr(mydate)) case else myDate = mid(0,instr(cstr(myDate),",")-1) & "th" & mid(instr(mydate,","),len(cstr(mydate)) end select Do you think that would do the trick? |
|
#6
|
|||
|
|||
|
This will stop working if the application is used outside the USA since most countries have day before month. You might need to check the locale before applying your adjustment.
|
|
#7
|
||||
|
||||
|
either that, or you can use the format$() function call to set all dates equal to a standard format before processing.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > VB Date format |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|