Working with DateTime Data

Slides:



Advertisements
Similar presentations
Server-Side Scripting with JSP (2) ISYS 350. Post Back A postback is call to the same page that the form is on. In other words, the contents of the form.
Advertisements

Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
C# Introduction ISYS 512. Major Differences Between VB Project and C# Project The execution starts from the Main method which is found in the Program.cs.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 1A) UTPA – Fall 2011.
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
C# Introduction ISYS 350. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
INTRODUCTION TO PYTHON. 1. The 5 operators in Python are: + - * / %
C# Introduction ISYS 512. Visual Studio 2013 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
C# Introduction ISYS 350. Visual Studio 2013 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
Chapter 5 The String and DateTime Data Types. Class 5: String & DateTime Understand the use of characters and strings Call members of the String class.
CS0004: Introduction to Programming Project 1 – Lessons Learned.
Expression and Decision Structure ISYS 350. Performing Calculations Basic calculations such as arithmetic calculation can be performed by math operators.
Sha Tin Methodist College F.4 Computer Studies Pascal Programming.
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
Decision Structure - 2 ISYS 350. Complex Condition with Logical Operators The logical AND operator (&&) and the logical OR operator (||) allow you to.
Dates and Times. Slide 2 Introduction to Dates and Times (1) The DateTime data type is used to store dates and times There is a date part There is a time.
Server-Side Scripting with JSP (2) ISYS 350. Java Array Examples of declaring an array: – int[] anArray = new int[10]; 10 elements index from 0 to 9 –
Research Topics in Computational Science. Agenda Commenting Our Code Variable Review Button Program – Add Textbox Getting text from textbox Converting.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Calendars, DateTime, Variables, and performing calculations on dates WSU – MIS171 Mauricio Featherman, Ph.D.
C# Introduction ISYS 350. Visual Studio 2012 Demo Start page: New project/ Open project/Recent projects Starting project: File/New Project/ –C# –Windows.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
31/01/ Selection If selection construct.
DateTime, Code Regions, and Multiple Form Applications Part13dbg.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Visual Basic Declaring Variables Dim x as Integer = 0 In the statement above, x is being declared as an Integer (whole number) and is initialised.
IS 350 Strings and Dates. Slide 2 Objectives Understand character-encoding systems and use the Char data type Use the String data type Call members of.
Java for Beginners University Greenwich Computing At School DASCO
Calculating age and choosing a SWYC form
Working with Date ISYS 350.
14 Shipping Time App Using Dates and Timers
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Decision Structure ISYS 350.
Quiz # 02 Design a data type Date to hold date
MIS Professor Sandvig MIS 324 Professor Sandvig
Java String and Date ISYS 350.
C# Introduction ISYS 350.
C# Introduction ISYS 350.
Introduction to Scripting
Computer Science 3 Hobart College
© 2016, Mike Murach & Associates, Inc.
CSC141 Computer Science I Zhen Jiang Dept. of Computer Science
Java Date ISYS 350.
HW2 VB .Net Loan Payment Due in class Friday 22 November
Tutorial 12 – Security Panel Application Introducing the Select Case Multiple-Selection Statement Outline Test-Driving the Security Panel Application.
Properties 7: Properties Programming C# © 2003 DevelopMentor, Inc.
Work with Data and Decision Structure
Lecture Set 6 The String and DateTime Data Types
Chapter 3: Introduction to Problem Solving and Control Statements
Equations with Variables on Both Sides Day 2
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 1/15/2019.
Java Date ISYS 350.
        CALCULATING THE MATURITY DATE 1 2 CALCULATING INTEREST
Conditional Logic Presentation Name Course Name
JavaScript.
See requirements for practice program on next slide.
Using string type variables
Java Date ISYS 350.
Data Type Conversion ICS2O.
Input, Variables, and Mathematical Expressions
Calculate 81 ÷ 3 = 27 3 x 3 x 3 3 x 3 x 3 x 3 ÷ 3 = This could be written as
Visual Basic Numbers Chapter 3.3 Prepared By: Deborah 7/9/2019.
Java Date ISYS 350.
COMPUTING.
Murach's JavaScript and jQuery (3rd Ed.)
Temporal Data Part V.
Working with dates and times
Presentation transcript:

Working with DateTime Data ISYS 350

Declare DateTime Variable Example: DateTime mydate; Convert date entered in a textbox to DateTime data: Use Convert: mydate = Convert.ToDateTime(textBox1.Text); Use DateTime class Parse method: mydate = DateTime.Parse(textBox1.Text); DateTime variable’s properties and methods: MinValue, MaxValue Year, month,DayOfWeek, hour, etc. AddYear,AddDays,AddHours, etc. Subtract ToLongDateString, ToShortDateString

DateTime Example DateTime myDate; myDate = DateTime.Parse(textBox1.Text); MessageBox.Show(myDate.ToLongDateString()); MessageBox.Show(DateTime.MinValue.ToShortDateString()); MessageBox.Show(DateTime.MaxValue.ToShortDateString());

How to calculate the number of days between two dates? TimeSpan class: TimeSpan represents a length of time. Define a TimeSpan variable: TimeSpan ts; We may use a TimeSpan class variable to represent the length between two dates: ts = laterDate-earlierDate;

Code Example DateTime earlierDate, laterDate; double daysBetween; TimeSpan ts; earlierDate = DateTime.Parse(textBox1.Text); laterDate = DateTime.Parse(textBox2.Text); ts = laterDate-earlierDate; daysBetween = ts.Days; MessageBox.Show("There are " + daysBetween.ToString() + " days between " + earlierDate.ToShortDateString() + " and " + laterDate.ToShortDateString()); Note: Pay attention to how we create the output string.

Useful Properties and Method Get current date: DateTime thisDate=DateTime.Today; Get current date and time: DateTime thisDate=DateTime.Now; Calculate # of days between two dates: myDate = DateTime.Parse(textBox1.Text); DaysBetween = thisDate.Subtract(myDate).Days;

Three Methods to Compute Age Given DOB: 1. Using Subtract method 2 Three Methods to Compute Age Given DOB: 1. Using Subtract method 2. Using Year property 3. Using TimeSpan Days DateTime myDate, thisDate = DateTime.Today; double Age; myDate = DateTime.Parse(textBox1.Text); Age = (thisDate.Subtract(myDate).Days / 365); MessageBox.Show(Age.ToString()); Age = thisDate.Year - myDate.Year; TimeSpan ts; ts = thisDate - myDate; Age = ts.Days / 365;

Compute Age Given DOB: Age<30, Young 30<=Age<65, Middle Age>=65, Old DateTime myDate, thisDate=DateTime.Today; double Age; myDate = DateTime.Parse(textBox1.Text); Age = (thisDate.Subtract(myDate).Days / 365); MessageBox.Show(Age.ToString()); If (Age<30) MessageBox.Show(“Young”); elseif (Age<65) MessageBox.Show(“Middle”); else MessageBox.Show(“Old”);

Date Comparison DateTime thisDate, currentDate = DateTime.Today; thisDate = DateTime.Parse(textBox1.Text); if (currentDate>thisDate) MessageBox.Show("after"); else MessageBox.Show("before");