Photo Gallery
Member List
Search
Calendars
FAQ
Ticket List
Log Out
Forums
Register
Login
My Profile
Inbox
Address Book
My Subscription
My Forums
Random Dates
Logged in as: Guest
arrSession:exec spGetSession 2,2,59619
Active Users: There are
0
members and
0
guests.
Users viewing this topic: none
Printable Version
All Forums
>>
[Scripting]
>>
WSH & Client Side VBScript
>> Random Dates
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 >>
Random Dates -
4/29/2008 1:20:29 PM
shahid09
Posts: 41
Score: 0
Joined: 1/22/2007
Status:
offline
Hi All,
Is there any way i can generate ranom date using two dates as a range.
Like random date between 01/01/2008 to 04/04/2008
Thanks,
SK
Post #: 1
RE: Random Dates -
4/29/2008 2:42:47 PM
TNO
Posts: 1064
Score: 10
Joined: 12/18/2004
From: thenewobjective.com
Status:
offline
Randomize
Dim Date1 : Date1 = CDate(Int((4 * Rnd) + 1) & "/" & Int((4 * Rnd) + 1) & "/2008")
MsgBox Date1
_____________________________
To iterate is human, to recurse divine.
-- L. Peter Deutsch
(in reply to
shahid09
)
Post #: 2
RE: Random Dates -
4/29/2008 5:23:34 PM
ehvbs
Posts: 2065
Score: 50
Joined: 6/22/2005
From: Germany
Status:
offline
Dim dtFrom : dtFrom = #4/13/2008# Dim dtTo : dtTo = #4/19/2008# ' half open range (upper bound exlusive) Dim nCnt : nCnt = 100 Dim dicDates : Set dicDates = CreateObject( "Scripting.Dictionary" ) Dim nFrom : nFrom = Fix( CDbl( dtFrom ) ) Dim nTo : nTo = Fix( CDbl( dtTo ) ) Dim nIdx WScript.Echo CDate( nFrom ), CDate( nTo ) For nIdx = 1 To nCnt Dim dtTest : dtTest = CDate( IRandR( nFrom, nTo ) ) ' WScript.Echo dtTest, nIdx dicDates( dtTest ) = dicDates( dtTest ) + 1 Next Dim dtIdx For dtIdx = dtFrom To DateAdd( "d", -1, dtTo ) WScript.Echo dtIdx, dicDates( dtIdx ) Next WScript.Quit 0 ''= generates 'random' integer between nFrom and (nTo - 1) ' ============================================================================ Function IRandR( ByVal nFrom, ByVal nTo ) IRandR = nFrom + Int( Rnd * (nTo - nFrom) ) End Function ------------ output -------------- === rndDate: random dates ======= 13.04.2008 19.04.2008 13.04.2008 16 14.04.2008 18 15.04.2008 16 16.04.2008 18 17.04.2008 16 18.04.2008 16 === rndDate: 0 done (00:00:00) ==
(in reply to
TNO
)
Post #: 3
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
>> Random Dates
Page:
[1]
Jump to:
Select a Forum
All Forums
----------------------
[Welcome]
- - Forum Rules
- - Test Posting Messages
- - New Member Area/Introduction
[Scripting]
- - WSH & Client Side VBScript
- - WSH & Client Side VBScript Tutorial
- - Post a VBScript
- - Windows PowerShell
- - ASP
- - ASP.NET
- - Windows Script Components
[General Forum]
- - Other Programming/Scripting Languages
- - Suggestions & Feedback
- - Off-Topic Lounge
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
Forum Software ©
ASPPlayground.NET
Advanced Edition
2.5.5 ANSI