Sign In | Subscribe
Start learning today, and be successful in your academic & professional career. Start Today!
Loading video...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Visual Basic
  • Discussion

  • Study Guides

  • Table of Contents

Bookmark and Share
Lecture Comments (2)

0 answers

Post by John Snape on July 27, 2014

The date format of #mm/dd/yyyy# is unchangeable mainly because if you hard code a date into your program, it has to be the same whether it is running in the United States or New Zealand or anywhere else. If you put in the date 2/11/1969 and your local date format is yyyy/mm/dd, then it would result in the date being November 1969, of the year 2, consequently throwing an error.

Because of this, you must always format your dates in any version of Visual Studio as mm/dd/yyyy. Hope that helps.

0 answers

Post by David Llewellyn on July 26, 2014

In the code download Ms Aniston's birthday was entered as 2/11/1969 which to a New Zealander, like me, means 2nd Nov '69 as opposed to the American 11th Feb '69.  When I ran the code, all the dates output in NZ/British type formats and the calculation of her age in days, confirmed in Excel, gives the correct difference of 16602 days.
When I altered the dates to what I would consider to be the correct format i.e. dd/mm/yyyy, Ms Aniston became 16,338 days old (i.e. her birthday was thought to be in November rather than February). Does #aa/bb/cccc# mean specifically US date format and is there some other delimiter for British format.

Dates & Times

  • The DateTime data type is used to hold dates and times
  • Strings use “” to delineate them, DatetIme uses ##
  • Now is used for the current date and time, Today is for the current date and midnight time
  • You can use the String.Format or ToString methods to format your dates and times
  • Some properties of DateTime:
    • .DayOfWeek
    • .Hour
    • .Month
    • .Millisecond
  • You can add or subtract dates and times like you would any other variable
  • .TotalMinutes and .TotalSeconds are other useful methods
  • Some useful methods of DateTime:
    • .AddDays
    • .AddYears
    • .AddSeconds
  • To subtract from DateTime, add a negative amount
  • TimeSpan allows you to give a generic timespan without reference to a specific day or time