Skip to Content
VBScript in a Nutshell, 2nd Edition
book

VBScript in a Nutshell, 2nd Edition

by Paul Lomax, Matt Childs, Ron Petrusha
March 2003
Intermediate to advanced
512 pages
14h 30m
English
O'Reilly Media, Inc.
Content preview from VBScript in a Nutshell, 2nd Edition

Name

DateSerial Function

Syntax

DateSerial(year, month, day)
year

Use: Required

Data Type: Integer

Number between 0 and 9999, inclusive.

month

Use: Required

Data Type: Integer

Any numeric expression to express the month between 1 and 12.

day

Use: Required

Data Type: Integer

Any numeric expression to express the day between 1 and 31.

Return Value

A Date.

Description

Returns a Date from the three date components (year, month, and day). For the function to succeed, all three components must be present and all must be numeric values.

Rules at a Glance

  • If the value of a particular element exceeds its normal limits, DateSerial adjusts the date accordingly. For example, if you tried DateSerial (96,2,31)—February 31, 1996—DateSerial returns March 2, 1996.

  • You can specify expressions or formulas that evaluate to individual date components as parameters to DateSerial. For example, DateSerial (98,10+9,23) returns 23 March 1999. This makes it easier to use DateSerial to form dates whose individual elements are unknown at design time or that are created on the fly as a result of user input.

Example

Dim iYear, iMonth, iday

iYear = 1987
iMonth = 3 + 11
iday = 16

MsgBox DateSerial(iYear, iMonth, iday)

Programming Tips and Gotchas

  • If any of the parameters exceed the range of the Integer data type (-32,768 to 32,767), an error (runtime error 6, “Overflow”) is generated.

  • The Microsoft documentation for this function incorrectly states, “For the year argument, values between 0 and 99, inclusive, are interpreted as the years ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

VBScript in a Nutshell

VBScript in a Nutshell

Matt Childs, Paul Lomax, Ron Petrusha
ASP in a Nutshell, 2nd Edition

ASP in a Nutshell, 2nd Edition

A. Keyton Weissinger
VBScript Programmer's Reference, Third Edition

VBScript Programmer's Reference, Third Edition

Kathie Kingsley-Hughes, Daniel Read, Adrian Kingsley-Hughes

Publisher Resources

ISBN: 0596004885Errata Page