Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 2nd, 2004, 12:26 PM
tOeJaM tOeJaM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: United States
Posts: 46 tOeJaM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 55 sec
Reputation Power: 6
Question VB Date format

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.

Reply With Quote
  #2  
Old January 2nd, 2004, 12:54 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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?

Reply With Quote
  #3  
Old January 2nd, 2004, 01:44 PM
tOeJaM tOeJaM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: United States
Posts: 46 tOeJaM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 55 sec
Reputation Power: 6
VB Date format

Thanks for the repsonse Fisherman.

No, this is for display purposes only so it's a string.

Reply With Quote
  #4  
Old January 2nd, 2004, 02:13 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
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

Reply With Quote
  #5  
Old January 2nd, 2004, 02:18 PM
tOeJaM tOeJaM is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: United States
Posts: 46 tOeJaM User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 55 sec
Reputation Power: 6
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?

Reply With Quote
  #6  
Old January 3rd, 2004, 07:49 PM
robbage robbage is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Location: Perth, Western Australia
Posts: 30 robbage User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to robbage
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.

Reply With Quote
  #7  
Old January 3rd, 2004, 08:46 PM
Fisherman's Avatar
Fisherman Fisherman is offline
Inherits Programmer.Slacker
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: Between my Id and your Ego
Posts: 2,178 Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level)Fisherman User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 56 m 45 sec
Reputation Power: 111
Send a message via ICQ to Fisherman Send a message via AIM to Fisherman
either that, or you can use the format$() function call to set all dates equal to a standard format before processing.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > VB Date format


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT