Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Date conversions

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,840
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Date conversions
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Date conversions - 5/14/2003 9:58:25 AM   
  Twuni

 

Posts: 1
Score: 0
Joined: 5/14/2003
From: USA
Status: offline
Try as I will, I cannot get this to work. There must be something I am missing. Here, take a look...

First off, let me familiarize you with what I am trying to do and my method to achieve it. I want to generate a television schedule using a single date in a database. The show airs on Wednesdays, Fridays, and Sundays, with a new episode on Wednesday. My script will generate two days, given the Wednesday airing. I could just as easily have done this with separate dates in the database, but since the schedule is firm, automated follow-up dates seem to be the best method instead of trips back and forth, and this allows for much easier administration (instead of changing six dates one only has to change two).

Anyway, my problem: I have written my subfunction to assign the dates to values in an array. FullSchedule( 1 ) holds the initial date -- Wednesday. My problem is that on some episodes (or maybe just some values for the InitialDate), the subfunction only seems to add 1 to the InitialDate to come up with the second date (but always adds two for the third, which is right). This is the portion of the script that I believe is causing the problem...

Dateconversions.asp
 
'Initialize variables
Dim FunctionCounter, FunctionYear, MonthDaysList, MonthNamesList, FunctionMonth, FullSchedule( 6 )

MonthDaysList = Array(31,28,31,30,31,30,31,31,30,31,30,31)
MonthNamesList = Array( "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" )

'Given a date, returns the day number of the year
Function DateToDay( MonthUsing, DayUsing, YearUsing )

'Initialize the return value as an integer and make sure the counter is reset
DateToDay = 0
FunctionCounter = 0

For FunctionCounter = 1 To ( MonthUsing - 1 )

DateToDay = Eval( DateToDay + MonthDaysList( FunctionCounter ) )

Next

'Reset the counter
FunctionCounter = 0

If ( YearUsing MOD 4 ) AND ( MonthUsing > 2 ) Then DateToDay = Eval( DateToDay + 1 )

DateToDay = Eval( DateToDay + DayUsing )

End Function

'Given the day number of the year, returns the date.
Function DayToDate( DayNumber, ThisYear )

'Make sure the counter is reset
FunctionCounter = 0

'Subtract the day totals of each month until the DayNumber is less than the value for the attempted month.
Do Until DayNumber <= 31
DayNumber = Eval( DayNumber - MonthDaysList( FunctionCounter ) )
FunctionCounter = Eval( FunctionCounter + 1 )
Loop

FunctionMonth = Eval( FunctionCounter + 1 )

If ( ThisYear MOD 4 ) AND ( FunctionMonth > 2 ) Then DayNumber = Eval( DayNumber - 1 )

DayToDate = FunctionMonth & "/" & DayNumber & "/" & ThisYear

If IsDate( DayToDate ) Then
DayToDate = CDate( DayToDate )
Else
DayToDate = Null
End If

'Reset the counter
FunctionCounter = 0

End Function

'GetFullSchedule()********************************************
' Assigns an array the following values
' 1 = First airtime of the week ( Wednesday ) Date
' 2 = Second airtime of the week ( Friday ) Date
' 3 = Third airtime of the week ( Sunday ) Date
' 4 = First promotion day for the week ( Monday ) Day
' 5 = Last promotion day of the week ( Sunday ) Day
' 6 = Year Number
'
' To use, simply assign an array to this function
'*************************************************************

Sub GetFullSchedule( InitialAirtime, BaseYear )

'Can be called with either a date or a day
If ( NOT IsDate( InitialAirtime ) ) AND ( InitialAirtime <= 365 ) Then InitialAirtime = DayToDate( InitialAirtime, BaseYear )

'Write the first value as the initial date
FullSchedule( 1 ) = InitialAirtime

'Assign the year used to the sixth value
FullSchedule( 6 ) = Year( InitialAirtime )

'Convert the airtime to day number
InitialAirtime = DateToDay( Month( InitialAirtime ), Day( InitialAirtime ), Year( InitialAirtime ) )

'Assign a date to the second value as two days after the first airtime
FullSchedule( 2 ) = Eval( 2 + InitialAirtime )
If Eval( FullSchedule( 2 ) - InitialAirtime ) = 2 Then FullSchedule( 2 ) = DayToDate( FullSchedule( 2 ), FullSchedule( 6 ) )

'Assign a date to the third value as four days after the first airtime
FullSchedule( 3 ) = DayToDate( Eval( 4 + InitialAirtime ), FullSchedule( 6 ) )
If Eval( FullSchedule( 3 ) - InitialAirtime ) = 4 Then FullSchedule( 3 ) = DayToDate( FullSchedule( 3 ), FullSchedule( 6 ) )

'Assign a day number to the fourth value as the first promotional day (two days before the first airtime)
FullSchedule( 4 ) = Eval( InitialAirtime - 2 )

'Assign a day number to the fifth value as the last promotional day (four days after the first airtime)
FullSchedule( 5 ) = Eval( 4 + InitialAirtime )

End Sub


___________________________________________
Albeit shimmer o' the twilight autumn
Darker in mine eyes
"O how I loathe thee so," a muted whisper cries
Lonesome in disguise.

Edited by - Twuni on 05/14/2003 16:01:15
 
 
Post #: 1
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Date conversions Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts