Director News
Director Web Sites
Mailing Lists
News Groups
Project Examples
Useful Web Sites

Don't miss these
import and play sound file (during runtime)
Catpure Source Read And Save ASF File
Cut Behavior (Ctrl + X)
SWFText - Flash Text Animation Builder to make Flash Intro and Banner with 180+ Effects
Vector Shapes - Create Spiral & Create Spiral Twist
Popup Text List Menu
Image Resizer v1.0



Article Manipulating Date and Time using Lingo

Added on 10/8/2000


D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: durbnpoisn (website)

I can retrieve the date and the time using Lingo, but how can I use it for anything aside from a simple clock?

Get the source
This is a great topic for anyone writing a program that needs to make determinations based on how much time has passed, or the time remaining to a particular point, or a graphic of an analog clock. Being able to manipulate the system date and time is FAR easier in some other languages because you normally can perform math on any segment of the returned value like it were any other integer. Performing this task in Lingo involves manual conversion of the returned value from a String to Integer values. This article explains what you'll need to know in order to do that.
See the Director Help file for more specific information on these functions.
(Exhibit 1)

Retrieving the date and time
There are a couple of different ways to retrieve the date and time:

the date : returns a string value "10/05/00" (The amount of digits for the year is dependent on the users Regional Settings)
the long date: returns a string value "Thursday, October 05, 2000"
the systemdate : returns integer values in a list: date(2000, 10, 5)
the time : returns a string value "9:26 AM" - this is never returned in military format, it is always formatted am/pm style
the long time : returns a string value "09:26:20 AM"

All of this seems like it would be very helpful, but, in some respects it's not helpful at all. For all that Lingo does to pre-format the date and time, it doesn't offer any way to really work with that information once you receive it. It's really just intended for you to dump these values out to the screen in a field.
This is true with one exception; the systemdate() function is returned with integers so it is possible to perform mathematic operations without any conversion.

Formatting and working with the date
After showing those examples, I must point out that the only one that really applies to this article is the systemdate function.
There's 2 good reasons for this:
1. It's already formatted in integer values.
2. Its format is not defendant on the users Regional Settings like the others are.

Knowing that, here are some examples on what you should expect to see when manipulating these values. Since there's so many different things you can do with these values, it's up to you to figure out how to display results to the user.

DateWithOffSet = the systemdate
--DateWithOffSet will now equal (2000, 10, 5) and DateWithOffSet is now a date object (it's necessary to do this in case you need to set the DateWithOffSet to another value, you cannot set the systemdate)

Now that DateWithOffSet is an object with 3 parts, any of them can be accessed individually, like this:
NextMonth = DateWithOffSet.month + 1
--NextMonth will equal 11
InTwentyDays = + 20
--InTwentyDays will equal 25
NextYear = DateWithOffSet.year + 20
--NextYear will equal 2001

(And my favorite - simple addition or subtraction the the systemdate always affects just the days but automatically counts the months and years as well - this also applies when working with a variable created as a date object)
InAFewDays = DateWithOffSet + 35
--InAFewDays will now equal (2000, 11, 9)

Formatting the Time string
Time functions don't have an equivalent to the systemdate function. This seems silly to me that Macromedia left this out, but, what can you do?
As a result of this oversight, you'll need to manually break apart the time after it's returned as a string.
There are thousands of ways to do this, and this is just one that I'm fond of:

curTime=word 1 of the long time
AmOrPm=word 2 of the long time
set the itemDelimiter to ":"
tHour=value (item 1 of curTime)
tMinutes = value (item 2 of curTime)
tSeconds = value (item 3 of curTime)

What you will have when this is done is all the integers you'll ever need to work with the time. What you choose to do with it from there is up to you.

I hope you find this article helpful.



36 South Court Sq
Suite 300
Newnan, GA 30263

Send e-mail