In fact, the names and functions of Date functions in different Pascal compilers vary. To learn more about date and time in Pascal, readers can refer to the content of this article by Mytour.
Retrieving Current Date and Time in Pascal
Pascal's TimeToString Function returns the current date and time result in colon-separated format (:). Below is an example of how to retrieve the current date and time in Pascal:
when the above code is compiled and executed, it will return the following result:
Current time: 18:33:08
The Date function returns the current date value in TDateTime format. TDateTime is a double value that needs to be decoded and formatted. The example below illustrates how to use the Date function in the program to display the current date:
After compiling and executing the code snippet, it will return the following result:
Date: 4.111300000000000E+004
Today's date (DD/MM/YY): 23/7/2012
The Now function returns the current date and time result:
After compiling and executing the code snippet, it will return the following result:
Date and Time at the time of writing: 23/7/2012 18:51:
Free Pascal provides a simple Time Stamp structure named TTimeStamp, formatted as shown below:
Date and Time Functions in Pascal
Free Pascal offers support for the following date and time functions:
The example below illustrates the usage of some of the above functions:
After compiling and executing the code snippet, it will return the following result:
Here are all the detailed information about date and time in Pascal as well as the date and time functions used in Pascal. Once you've learned about date and time functions, you can also explore how to write functions in Pascal. The next article by Mytour will further introduce you to classes in Pascal. Don't forget to share your opinions and ratings with Mytour!
