Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2004, 06:28 PM
Registered User
 
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default FlexGrid and Date Fields

I am using an MsFlexGrid to display data from an Access 2000 database using ADO code, not an ADO control. A date field will always diaplay in the mm/dd/yyyy format. The fields is formatted in Access as dd/mm/yyyy and I would like it to retain this format in the grid.

The only way I have found to get the dd/mm/yyyy format, is to use the Format function and then format the date using "mm/dd/yyyy" as the format string??

If the FlexGrid is bound to an ADO data control, the data displays OK, using the formatting from the Access table definition. However, I need to use code rather than the ADO data control.

Can anyone please let me know if there is a simpler (or better) way to display dates with the dd/mm/yyyy format in a FlexGrid control?

Karen.

 
Old May 26th, 2004, 02:44 AM
Authorized User
 
Join Date: May 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to myedu2k4
Default

I think there is no simplier way to do it.
Maybe other has an idea...

Pheap

 
Old September 28th, 2004, 08:37 AM
Authorized User
 
Join Date: Sep 2004
Posts: 55
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Lalit_Pratihari
Default

Hi,

Whatever case maybe you can try the following:

If you want to convert a date into DD/MM/YYYY format:

Public Function DDMMYYYY(byVal MyDate)
'This Function Takes Any Valid Date And Returns DD/MM/YYYY

    Dim MyDay
    Dim MyMonth
    Dim MyYear
    Dim MyDay2
    Dim month2

    If IsDate(MyDate) Then
        MyDay = Day(MyDate): MyMonth = Month(MyDate): MyYear = Year(MyDate)
        If Len(MyDay) = 1 Then
            MyDay2 = "0" + CStr(MyDay)
        Else
            MyDay2 = CStr(MyDay)
        End If
        If Len(MyMonth) = 1 Then
            month2 = "0" + CStr(MyMonth)
        Else
            month2 = CStr(MyMonth)
        End If
        DDMMYYYY = MyDay2 + "/" + month2 + "/" + CStr(MyYear)
    End If
End Function

If you want to convert a date into MM/DD/YY format:

Public Function MMDDYY(ByVal MyDate)
'This Function Takes DD/MM/YYYY And Returns MM/DD/YY
    Dim MyDay
    Dim MyMonth
    Dim MyYear
    Dim length
    Dim position1 As Integer
    Dim position2 As Integer
    If IsDate(MyDate) Then
        length = Len(MyDate)
        position1 = InStr(CInt(1), MyDate, "/")
        position2 = InStr(position1 + 1, MyDate, "/")
        MyDay = Left(MyDate, position1 - 1)
        MyMonth = Mid(MyDate, position1 + 1, (position2 - position1 - 1))
        MyYear = Right(MyDate, 2)
        MMDDYY = MyMonth + "/" + MyDay + "/" + MyYear
    End If
End Function

Hope this helps,

Lalit
Life Means More...;)
 
Old September 28th, 2004, 08:50 AM
Authorized User
 
Join Date: Jun 2003
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another routine that i use is

Public Function FormatDate(ByVal dDateField As Date, ByVal sFormatField As String) As String
FormatDate = Format(dDateField, sFormatField)
End Function

eg myDate = FormatDate(varDate,"mm/dd/yyyy")

HTH

Byron

 
Old September 28th, 2004, 08:50 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

why use a function when you have the format to do it???

what's your problem with format????

HTH

Gonzalo





Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking table Date fields by month wintermute Access VBA 4 April 3rd, 2008 04:35 AM
Filter form with date fields problem!! chiefouko Access 2 August 14th, 2006 10:15 AM
Trouble with comparing date fields JimmyNeutron Access VBA 3 February 22nd, 2005 09:14 AM
SELECT LIKE on DATE fields borami Classic ASP Databases 2 March 16th, 2004 11:43 AM
SELECT LIKE on DATE fields borami Classic ASP Databases 0 March 16th, 2004 08:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.