Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual 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 ASP Free Forums Sponsor:
  #1  
Old September 2nd, 2005, 08:24 AM
thayalan44 thayalan44 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 29 thayalan44 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 10 m 55 sec
Reputation Power: 0
Date Formatting in VB Code

I have a sample code shown below which checks for certain dates and display appropriate messages. The codes shown below which are part of a software package will be installed in more than one computer with various date settings (dd-mm-yy, mm/dd/yy, etc.) To test the future, I have set the date settings on my computer to yyyy-mm-dd. I thought the Format function in the Code shown below will have the value for TodaysDate in the dd-mm-yy format. But, I am having the format in the yyyy-mm-dd format which is the computer's date setting. Can anyone please tell me how to have the date settings format for the variable TodaysDate in the dd-mm-yy format?



Code:

    Dim TodaysDate As Date
    
    TodaysDate = Format(Now, "dd-mm-yy")
    If TodaysDate > "02-09-05" Then
       MsgBox "License has expired."
       Exit Sub
    ElseIf TodaysDate = "24-09-05" Then
       MsgBox "10 days for the license to expire."
    Else
       '
    End If

Reply With Quote
  #2  
Old September 2nd, 2005, 01:00 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 23 h 29 m 58 sec
Reputation Power: 181
You can build your own date format by using the DatePart() function to break the date/time up into it's component parts. Also you might look at the Format() maybe there is a pre-built format that will work for you.

Something like:
Code:
strDay = DatePart("d", theDate)
strMonth = DatePart("n", theDate)
strYear = DatePart("y", theDate)
newDate = strDay & "-" & strMonth & "-" & strYear


Refer to the DatePart documentation to see the different date and time components you can extract individually from a datetime value.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Date Formatting in VB Code


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 3 hosted by Hostway
Stay green...Green IT