如何从日期获得月份和年份

Jet*_*ack -1 vb6

如何从日期获得月份和年份

Date = 01/02/2012 (dd/mm/yyyy)
Run Code Online (Sandbox Code Playgroud)

从上面的日期开始,我想得到 02/2012 (mm/yyyy)

如何在vb6中编写代码

需要vb6代码帮助

Dar*_*ren 7

您可以使用带有Date参数的Month()Year()函数.

Month(Now)返回月份并Year(Now)返回年份.

Dim yourDate As Date
yourDate = #01/02/2012#

Dim yourMonth As Integer
Dim yourYear As Integer
yourMonth = Month(yourDate)
yourYear = Year(yourDate)
Run Code Online (Sandbox Code Playgroud)


C-P*_*uru 6

你可以使用Format$:

Dim formattedDate as String
Dim myDate as Date

myDate = #1/2/2012#
formattedDate = Format$(myDate, "mm/yyyy")
Run Code Online (Sandbox Code Playgroud)