tags:

views:

60

answers:

1

Using VB 6

Using two DTPicker in my project, I want to select monthly and yearly like MM/yyyy and yyyy

Now am Using Daily Date’s like 23/02/2009 (dd/MM/yyyy), I want to use like Monthly (MM/yyyy) and Yearly (yyyy)

My Code

Public Function DaysInMonth(dte As Date) As Integer
    Dim d As Date
    d = DateAdd("m", 1, dte)
    d = DateAdd("d", -1, d)
    DaysInMonth = Day(d)
End Function

Private Sub Form_Load()

Dim dteFrom As Date
Dim dteTo As Date
dteFrom = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & "01"), "yyyy-mm-dd")
dteTo = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & DaysInMonth(dteFrom)), "yyyy-mm-dd")

dtpFrom.Value = dteFrom
dtpTo.Value = dteTo

End Sub

Above code is working for daily dates. I want to use monthly and yearly dates also Now I am selecting a date it showing complete value of the date like 03-02-2009, I want to show monthly and Yearly data’s

Expected Output.

Monthly Date

03/2009 to 04/2009 – It should take a value of 01/03/2009 to 30/04/2009
05/2009 to 05/2009 – It should take a value of 01/05/2009 to 31/05/2009

Yearly Date

2008 to 2008 – It should take a value of 01/01/2008 to 31/12/2008
2008 to 2009 – It should take a value of 01/01/2008 to 31/12/2009

How to select monthly and yearly?

Need VB 6 code Help

+1  A: 

You can set the Format on the DTPicker to 3 (dtpCustom) and the CustomFormat to MM/yyyy . This will display month/year format in the text section, but you will still get the full calendar on drop down.

If you want to disable the calendar, you can set UpDown to True. Then you will get up/down buttons instead of the dropdown.

You need to make sure that the hidden value (day part) is correct.

EDIT: OK, from your comment I understand that you are happy with the date picker, but you want to display the result in a special format?

Example:
Date selected is 20/8/2009 and stored in a date variable a.

Display as 2009:

MsgBox Format(a, "yyyy")

Display as 08/2009:

MsgBox Format(a, "mm/yyyy")

Display as August, 2009:

MsgBox Format(a, "mmmm, yyyy")

Display as Aug, 2009:

MsgBox Format(a, "mmm, yyyy")

Is this what you want?

awe
@awe. I get the Date value, like a = dtpicker1, msgbox(a) it showing 01/02/2009. It should show 02/2009. And also when am selecting a date like 01/2009 to 01/2009. The Record is displaying for one day. It should display January (31 days) record. How to modify my code. Please ....
Gopal
I changed my answer to add an example, is this what you want?
awe