Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips > Tutorials
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Tutorials Basic4ppc tutorials


Date and Time


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-24-2007, 09:05 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 2,725
Default Date and Time

Basic4ppc stores date and time values as ticks.
Each tick represents 1 / 10,000,000 of a second and counting starts at January 1, AD 0001.
This post was written on September 23, 2007 which is 633261705083378192 ticks.
It is more convenient to store the values as a number, because date and time formats could vary.
There are two pairs of keywords that transfer a ticks value to a formatted string (Date and Time) and vice versa (DateParse and TimeParse).
Now returns the ticks value of the current time.
So if we want to show the current date and time (string formatted):
Code:
Msgbox(Date(Now) & " " & Time(Now))
DateFormat and TimeFormat keywords set the date and time string format.
The default formats are:
DateFormat("mm/dd/yyyy")
TimeFormat("HH:mm") - 24 hours format.
See the help manual for more information about the formats.
DateParse and TimeParse convert a string formatted date or time to a ticks value.
The string format must exactly match the DateFormat and TimeFormat values (or the default values).
So if we want to store a specific date or we want to use a date given by the user we will use:
Code:
d = DateParse("02/03/2004")
Msgbox("String: " & Date(d) & crlf & "Ticks: " & d)


The actual time that this value represents is February 03, 2004 00:00 AM.
If we use TimeParse we will get a value that represents the time specified and the date will be today.
For example:
Code:
d = TimeParse("12:30")
Msgbox("Date: " & Date(d) & crlf & "Time: " & Time(d))
This code will show today's date and 12:30.
Keywords like DateMonth or TimeHour return a specific date or time component from a ticks value.
DateAdd and TimeAdd return a new ticks value after adding the required years, months...
If we want to add 7 days to a specific date:
Code:
d = DateAdd(d,0,0,7)
As ticks are just numbers, they could be used inside all kinds of calculations.
There are four date and time constants:
  1. cTicksPerDay
  2. cTicksPerHour
  3. cTicksPerMinute
  4. cTicksPerSecond
To calculate the number of days between two dates:
Code:
d1 = DateParse("04/30/2006")
d2 = DateParse("04/30/2007")
Msgbox(Int((d2-d1)/cTicksPerDay)) 'will show 365
To get the value of a specific date and time:
Code:
d = DateParse("04/30/2006") + (TimeParse("13:35") Mod cTicksPerDay)
Msgbox(Date(d) & " " & Time(d)) 'will show 04/30/2006 13:35
You can use the Calendar control to allow the user to choose a specific date.
The Calendar.Value property gets or sets the chosen date (as ticks).
Note that the Calendar has a Format property of its own.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
working with date gjoisa Questions & Help Needed 3 03-29-2008 09:40 AM
How to get the value of date substraction ? gjoisa Questions & Help Needed 1 02-11-2008 09:15 AM
How I have compare date? epatrik Questions & Help Needed 4 09-20-2007 09:54 AM
How to get saved date and time value or other properties of a file? Rioven Questions & Help Needed 1 08-30-2007 06:10 AM
filter for date manu Questions & Help Needed 2 06-09-2007 01:13 PM


All times are GMT. The time now is 06:38 PM.


Powered by vBulletin® Version 3.6.10
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0