VBA中的日期功能 [英] Date function in VBA

查看:47
本文介绍了VBA中的日期功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个工作表功能日期,其工作方式如下:

There is a worksheet funtion Date that works like this:

Date(2016; 03; 01) => 2016年1月3日

Date(2016;03;01) => 01.03.2016

但是,我在vba中找不到此功能. Application.WorksheetFunction.Date 不存在.而且 Date()只能在没有参数的情况下使用,以获取今天的日期.

However, I can't find this function in vba. Application.WorksheetFunction.Date does not exists. And simply Date() can only be used without arguments to get today's date.

在哪里可以找到该工作表函数Date的确切版本,该日期需要以年,月和日为参数?

Where do I find the exact version of that worksheet function Date, that takes year, month and day as arguments?

编辑:我不需要当前日期.我需要该函数与参数一起使用.

I don't need the current date. I need that function to use with arguments.

推荐答案

CDate 可以将String转换为Date,它支持各种输入格式.但是我建议先通过 IsDate 检查字符串.

CDate can convert String to Date, it supported various input formats. However I suggest checking the string by IsDate first.

DateSerial 可以通过将年,月,日指定为整数来生成日期.

DateSerial can generate a Date by giving Year, Month, Day as integer.

在示例中使用 DateSerial :

Dim myDate As Date

myDate = DateSerial(2016, 3, 1)

这篇关于VBA中的日期功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆