Jump to content



Photo

Generate Random DateTime Between Two Dates (UNIX)

random datetime date time unix

  • Please log in to reply
3 replies to this topic

#1 ikebukuro

ikebukuro

    Member

  • Fellow UBotter
  • PipPip
  • 24 posts
  • OS:Windows 8
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 10 September 2013 - 03:10 AM

Didn't find anything on the forum about this yet, so hopefully this will be useful to anyone searching how to do it in the future. Was using javascript to generate random dates before, but like this way better as it doesn't need a webpage.

 

You will need the free datetime manipulation plugin created by UBotDev.com: http://www.ubotstudi...e-manipulation/

 

Thanks should go to UBotDev.com for creating and giving out this very handy plugin for free. :)

 

Example code below:
 

define $Random DateTime(#date start, #date end) {
    set(#date start unix, $plugin function("DateTime Manipulation.dll", "$datetime manipulation", #date start, "M/d/yyyy", "UNIX", "en-US", "en-US"), "Local")
    set(#date end unix, $plugin function("DateTime Manipulation.dll", "$datetime manipulation", #date end, "M/d/yyyy", "UNIX", "en-US", "en-US"), "Local")
    return($plugin function("DateTime Manipulation.dll", "$datetime manipulation", $rand(#date start unix, #date end unix), "UNIX", "yyyy-MM-dd HH:mm:ss", "en-US", "en-US"))
}
ui text box("Start Date (M/d/yyyy)", #date start)
ui text box("End Date (M/d/yyyy)", #date end)
loop(3) {
    alert($Random DateTime(#date start, #date end))
}


Input format set to: M/d/yyyy
Output format set to: yyyy-MM-dd HH:mm:ss

Change it up to your preferred formats of course.

 

Useful for scheduling a batch of blog posts to random dates, or other purposes.



#2 Code Docta (Nick C.)

Code Docta (Nick C.)

    Member for Hire

  • Fellow UBotter
  • PipPipPip
  • 1591 posts
  • LocationIn a Python or UBot IDE or ubotdocta.com
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 10 September 2013 - 07:25 AM

Very cool!

UBot Expert Tutorials Store

ubot-docta-header-ubot-expert-store.png

 

 

Python and UBot expert tutorials and documentation


#3 UBotDev

UBotDev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 1395 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 10 September 2013 - 01:00 PM

Great example of usage, thanks for sharing the code.

 

I've just added a link to this topic from the original plugin page here on forum, I hope you don't mind.


CLICK UBotDev.com - Download FREE UBot Plugins!

______________________________________________

 


#4 ikebukuro

ikebukuro

    Member

  • Fellow UBotter
  • PipPip
  • 24 posts
  • OS:Windows 8
  • Total Memory:More Than 9Gb
  • Framework:v3.5 & v4.0
  • License:Developer Edition

Posted 12 September 2013 - 03:30 AM

I'm happy to hear that! Thanks again for the great plugin.







Also tagged with one or more of these keywords: random, datetime, date, time, unix

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users