|
-
Jul 25th, 2001, 08:18 PM
#1
Thread Starter
Frenzied Member
System Dates - Formating it
since vb dates depend on how the system date is formated
this is no good for me
how can i make sure that the date will ALWAYS be same format
"dd/mm/yyyy"
with leading 0's
such that its 07/25/2001
this has to work for no matter WHAT the system date format is like
some pick short, some pick long
some reverse the month and day, ect
i need
DAY FIRST, MONTH, YEAR (with leading zeros)
hope you guyz undrestand
format(now, "dd/mm/yyyy") doesnt work for all cases of formating the system date manually do a different one
-
Jul 25th, 2001, 10:03 PM
#2
Can you explain in what cases the Format function doesn'work? Because I have always been able to format it that way.
-
Jul 25th, 2001, 10:31 PM
#3
Thread Starter
Frenzied Member
ok
i could SWEAR it wasnt working
now it does
hmm
i will figure out whats going on
the come back
he he
do you like writing code for people serge?
if you do, i need some help he he
given
const STARTDATE = "01/01/1995"
EndDate = format(now, "mm/dd/yyyy")
so basically given a constatn start date
and todays date
i would like to populate a Treeview object as follow
since 1995 is the start year
i want it to start off with
Code:
1995
Jan
1
2
3
...(last day of that month for that year)
Feb
(same as above)
March (same as above
1996 (same as above)
......
2001 (same as above)
however, since 2001 is not complete, i dont want all the 12 months to be listed, and since today is let say 25th, i dont want no dates to be listed after july 25th
so the last date should be what EndDate is (logical)
i know how to do this
but i believe how i am doing this is not effecient so i am looking for a better solution
here is how i am doing it
sending in 2 dates into a class object
then the class object figures out how many years there is in between (inclusive) the 2 dates
and lists them (i will need this for the treeviews top nodes)
but it gets tricky when comes to the months
and how many days each of those months contain for that perticular year, i was gonna use a 2D array for month and what year they are, then i was gonna use a 3D array for day, month and year
after thinking about this, the code would get ugly
so i was hoping someone has a better solution
or have time that they would like to help me out to do this (ya am asking you to write the code for me IF you like)
attached is what i have done so far
-
Jul 26th, 2001, 01:23 PM
#4
It's fairly simply to do what you're asking, I also added the weekday name next to the day:
VB Code:
Private Sub Form_Load()
Dim intYear As Integer
Dim intMonth As Integer
Dim intDay As Integer
Dim nodYear As Node
Dim nodMonth As Node
Dim nodDay As Node
Dim intLastMonth As Integer
Dim intLastDay As Integer
Dim strTemp As String
Const STARTDATE = "01/01/1995"
With TreeView1
For intYear = Year(STARTDATE) To Year(Date)
Set nodYear = .Nodes.Add(, , "Year " & intYear, intYear)
If intYear = Year(Date) Then
intLastMonth = Month(Date)
Else
intLastMonth = 12
End If
For intMonth = 1 To intLastMonth
Set nodMonth = .Nodes.Add(nodYear, tvwChild, , MonthName(intMonth))
If intMonth = Month(Date) And intYear = Year(Date) Then
intLastDay = Day(Date)
Else
strTemp = Format("1/" & intMonth & "/" & intYear, "dd/mm/yyyy")
intLastDay = GetlastDayofMonth(CDate(strTemp))
End If
For intDay = 1 To intLastDay
strTemp = intDay & "/" & intMonth & "/" & intYear
Set nodDay = .Nodes.Add(nodMonth, tvwChild, , intDay & " (" & WeekdayName(Weekday(strTemp)) & ")")
Next
Next
Next
End With
End Sub
-
Jul 27th, 2001, 10:15 PM
#5
Thread Starter
Frenzied Member
where is?
GetlastDayofMonth (get error on it)
-
Jul 27th, 2001, 10:23 PM
#6
Sorry, forgot about that function:
VB Code:
Public Function GetlastDayofMonth(p_Date As Date)
GetlastDayofMonth = Day(DateSerial(Year(p_Date), Month(p_Date) + 1, 0))
End Function
-
Jul 27th, 2001, 10:38 PM
#7
Thread Starter
Frenzied Member
thank you so much
you saved me a lot of work 
i was gonna write a whole lota code for that 
tested it
works like a charm (gonna make few modifications to how the days are dispalyed.. but thats about it )
thanks again
-
Jul 27th, 2001, 10:47 PM
#8
Thread Starter
Frenzied Member
just noticed a little bug
if i change the start date in STARTDATE
it doesnt work
changing the year in it works fine
so if i pick 2001 it does it properly
but when i change the month and date
it always goes Jan-EndDate (with all those values)
even though if i had 07/20/2001, still puts jan-end date
thanks
-
Jul 27th, 2001, 11:11 PM
#9
PowerPoster
kovan, you can use the GetLocalelInfo and SetLocaleInfo to change the system date to any window recognize format you wish. Juz call this function when your app is loaded 
VB Code:
Option Explicit
'// WIN32 API Function
Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long
Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Long
'// WIN32 API Constant
Private Const LOCALE_SYSTEM_DEFAULT = &H800
Private Const LOCALE_USER_DEFAULT = &H400
Private Const LOCALE_SSHORTDATE = &H1F ' short date format string
Private Const LOCALE_SLONGDATE = &H20 ' long date format stringPrivate Const LOCALE_USER_DEFAULT = &H400
Private Const LOCALE_SDATE = &H1D ' date separator
Private Sub Form_Load()
Dim sLocale As String
Dim retVal As Long
sLocale = Space(255)
retVal = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, sLocale, Len(sLocale))
sLocale = Left(sLocale, retVal)
MsgBox "Old Short Date Format = : " & sLocale
sLocale = "dd/MM/yyyy"
retVal = SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, sLocale)
MsgBox "New Date Format = : " & sLocale
End Sub
regards,
-
Jul 28th, 2001, 12:05 AM
#10
Thread Starter
Frenzied Member
thanks everyone
got everything working just the way i want it
oh ya that date going out of wack
well it was my fault
he he
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|