Date and Time 
Author Message
 Date and Time

I have just recently started using Visual Basic 5 and need to be able to
work with the Date and Time objects.
Could somebody help me with-
formatting the output of the Date and Time and
how to subtract a time specified previously in an application from the
current time.

I hope this is clear enough



Mon, 21 May 2001 03:00:00 GMT  
 Date and Time




|I have just recently started using Visual Basic 5 and need to be able
to
|work with the Date and Time objects.
|Could somebody help me with-
|formatting the output of the Date and Time and
|how to subtract a time specified previously in an application from
the
|current time.

For formatting check the VB help file for the Format function (there
are examples there).

Check the DateDiff function in help for subtracting times.

;-) Cool
Hasta Luego
Adrian Maull, MCP


Mon, 21 May 2001 03:00:00 GMT  
 Date and Time
MyTime and MyDate are displayed in the development environment using current
system short time setting and short date setting.

Dim MyTime, MyDate, MyStr
MyTime = #17:04:23#
MyDate = #January 27, 1993#

' Returns current system time in the system-defined long time format.
MyStr = Format(Time, "Long Time")

' Returns current system date in the system-defined long date format.
MyStr = Format(Date, "Long Date")

MyStr = Format(MyTime, "h:m:s") ' Returns "17:4:23".
MyStr = Format(MyTime, "hh:mm:ss AMPM") ' Returns "05:04:23 PM".

MyStr = Format(MyDate, "dddd, mmm d yyyy") ' Returns "Wednesday,
 ' Jan 27 1993".
' If format is not supplied, a string is returned.
MyStr = Format(23) ' Returns "23".

' User-defined formats.
MyStr = Format(5459.4, "##,##0.00") ' Returns "5,459.40".
MyStr = Format(334.9, "###0.00") ' Returns "334.90".
MyStr = Format(5, "0.00%") ' Returns "500.00%".

MyStr = Format("HELLO", "<") ' Returns "hello".
MyStr = Format("This is it", ">") ' Returns "THIS IS IT".

This should help you format anything you want.  For more info, look up the
Format function in the Language reference in the Books Online of Visual
Basic.

Robert - MCSD



Mon, 21 May 2001 03:00:00 GMT  
 Date and Time

Oh...one more thing...Use the Datdiff function to get the number of days
between two dates

This example uses the DateDiff function to display the number of days
between a given date and today.

Dim TheDate As Date ' Declare variables.
Dim Msg
TheDate = InputBox("Enter a date")
Msg = "Days from today: " & DateDiff("d", Now, TheDate)
MsgBox Msg

Robert - MCSD



Mon, 21 May 2001 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. My datagrid cannot display full date and time (only date is shown)

2. Date - Date/time comparison - please help

3. How to Convert GMT(Greenwich) Time to short date and time and vice versa

4. How to get date and time from unix time in VB

5. Elapsed Time between two dates and times

6. Getting Server date and time

7. Date and Time Stamp for a Field Being Modified

8. Getting Date and time from the server

9. Date and time on the server

10. Help with Date and Time.

11. Date and Time Calculations

12. System Date and Time

 

 
Powered by phpBB® Forum Software