Results 1 to 3 of 3

Thread: FORMAT DATE CODE

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    strEndDate = Format("01 " & cboMonth & " " & cboYear, "dd/mm/yy")

    THIS CODE WORKS PERFECTLY, but returns 01/xx/xx
    I need it to return xx/31/xx so the variable cboMonth should be first the day is set and I need a return of the variable year.

    when I change the code to:

    strEndDate = Format("01 " & cboMonth & " " & cboYear, "dd/mm/yy") or any combinations I get xxx xxxx
    month and day together separtated by a 4 digit year when i need two. plus the "/" is completely gone. I think maybe its become a string or something; any ideas? I just need to swith cboMonth with the first string!!!

  2. #2
    Guest

    Question A bit confusing in what you want

    Do you require the date returned in US format, i.e mm/dd/yy???????????????????

    if so try

    strEndDate = Format(cboMonth & "/" & "01" & "/" & cboYear, _
    ,"mm/dd/yy")

    If not try explaining in clearer English

  3. #3
    Guest
    the description of what you want is a little awkward, here's some code that might help, i really didn't understand what you were looking for, do remember there are more functions than just Format, like DateSerial...
    Code:
    Option Explicit
    
    
    
    Private Sub cboMonth_Click()
          BuildDate
    End Sub
    
    Private Sub cboYear_Click()
          BuildDate
    End Sub
    
    Private Sub Form_Load()
          Init
    End Sub
    Public Sub Init()
          Dim intYear As Integer
          Dim intMonth As Integer
          
          For intYear = 1994 To Year(Now)
                Me.cboYear.AddItem intYear
          Next
          For intMonth = 1 To 12
                Me.cboMonth.AddItem MonthName(intMonth), intMonth - 1
          Next
    End Sub
    Public Function BuildDate()
          If IsNumeric(Me.cboYear) And Not (Me.cboMonth.Text = "Month" Or Me.cboMonth.Text = "") Then
                Dim dtNewDate As Date
                dtNewDate = DateSerial(Me.cboYear, Me.cboMonth.ListIndex + 1, "01")
                Me.lblDate = dtNewDate & "    " & WeekdayName(Weekday(dtNewDate))
          End If
    End Function
    this code assumes that you have two combo boxes named cboYear and cboMonth and a label named lblDate on a form who's name shouldn't matter. Every time you change the year or month the date will be regenerated and displayed. Good luck.

    here are the project files(6k zipped up):http://www.panteravb.com/data/DateTest.zip.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width