View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Getting Current Day/Time etc. by Sam Asghari

Created By: Sam Asghari

Oftentimes you'll want to retrieve and store the current day or current time of something that is being done (for our class project, we needed a day and time that a patients' medical record was created.) After some excruciating searching, the following was found to work:

dAndT := Date dateAndTimeNow "dAndT  now corresponds to #(December 2, 2009 10:08:46 am)"

We see d is now an immutable array with 2 elements. Each index in the array corresponds to:
  1. Date (Month Day, Year)
  2. Time (Hours:Minutes:Seconds am/pm)

Thus, to automatically retrieve the entire date we can use the following code:

date := dAndT  at: 1

And if we wanted to know what day of the month our date contained we could very easily do that. It is also very easy to figure out how many days are in the month given a current day.

date dayOfMonth "this would return the number 2 for the working example on this page"
date daysInMonth "this would return 31, which is the correct number of days in the month of December as per the example"

Alternatively, built-in functions can be used with time as well. If, for example we wanted to know only the hour at which our record was created the following code would be used

time := dAndT  at: 2 "gets the time object from our array"
time hours "returns the hour field from the time object. In the example being used here, 10 is returned

Links to this Page