davin kurniadi davin kurniadi - 2 months ago 16
Vb.net Question

make the specific number to become day of month

so i have this problem, i want to make specific number to become a day of month.
example: i had an output of label

now how to make it to become
? i just convert them into string like this

dim testing as string = ""
testing = Now.Year.ToString & Right("0" & Now.Month.ToString, 2) & Right("0" & "5" 2)

output :


and if i use string, i cannot compare it with

thanks before


DateTime has a constructor that takes the year, month and day of month as parameters that you can use to create an instance:

Dim dayOfMonth As String = "5"
Dim myDate = New Date(Date.Now.Year, Date.Now.Month, CInt(dayOfMonth))

You can use the ToString method to format the date however you need:

Dim format1 As String = myDate.ToString("yyyy-MM-dd")
Dim format2 As String = myDate.ToString("dd-MM-yyyy")