jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Laurent Perez" <hak...@gmail.com>
Subject Re: How to generate random dates
Date Thu, 23 Oct 2008 15:14:32 GMT
shameless blog copy and paste, looks good enough :

http://blogs.circlesource.com/2008/07/17/generating-random-datetime-between-2-different-datestimestamps-in-java/

(java code, if it does not adapt under javascript, you could use a
beanshell script within jmeter)

laurent

2008/10/23 Hiro Protagonist <hir0pr0tagoni3t@googlemail.com>:
> Andrey, All,
>
> I can't seem to get it to generate random dates that have to lie between
> two date boundaries. I've tried sth like this (hack !!):
>
> ${__javaScript(
> var today_date=new Date();
> var old_date=new Date();
> old_date.setDate(today_date.getDate()-5);
> var old_date_int = old_date.getTime();
> var today_date_int = today_date.getTime();
> var random_date_int=old_date_int
> +(Math.random()*(today_date_int-old_date_int));
> random_date_int.toUTCString();)}
>
> but when I use this it doesn't evaulate. Does anyone have anything
> 'out-of-the-box' that works ?
>
> TIA
> hiro
>
> On Thu, 2008-10-23 at 16:05 +0400, Andrey Beznogov wrote:
>> Hi,
>>
>> the best way would be probably randomizing the Time part (the number
>> of milliseconds since 1970/01/01) of the Date(). For example in
>> javascript
>>
>> var mydate=new Date();
>> mydate.setTime(mydate.getTime()*Math.random());
>> mydate.toUTCString();
>>
>> will output a date string in UTC format (like "Sat, 19 Jan 1985
>> 06:22:28 GMT") for a date between now and 1970/01/01.
>>
>> Regards,
>> Andrey
>>
>> On Thu, Oct 23, 2008 at 3:47 PM, Hiro Protagonist
>> <hir0pr0tagoni3t@googlemail.com> wrote:
>> > Hi team,
>> >
>> > I need to generate random dates in JMeter. I know that by merely using
>> > the random function and then 'building' the date string I can get 90% of
>> > the way there - however, in order no to risk faulty dates, I always lose
>> > out on dates after the 28th.
>> > The obvious problem here is the interdependency between the months and
>> > their respective number of days.
>> > Does anyone know of a quick and easy solution ?
>> >
>> > Thanks !
>> >
>> > hiro
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>> >
>> >
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>



-- 
<a href="http://in-pocket.blogspot.com">http://in-pocket.blogspot.com
- Mobile world, technology and more</a>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Mime
View raw message