Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2013
    Posts
    1

    Unanswered: Random date selection

    I have a mainframe / Db2 application, have a requirement to select random between two dates .i.e within a month, within a quarter..also it needs to select date between Monday thru Friday... Is there any function in COBOL or DB2 to get a random date?

    Appreciate if you shed any light..

    Thanks, Kesava

  2. #2
    Join Date
    Apr 2013
    Posts
    2

    Selecting a random date

    Good Day Kesava,

    I would make use of the rand function to generate a random number to add or subtract days/months etc. Take a look at the infocenter IBM Information Management Software for z/OS Solutions Information Center.

    For example if you wanted to generate a random day in January 2013 you could do:

    SELECT DATE('2013-01-01') + (INT(RAND()*31)) DAYS FROM SYSIBM.SYSDUMMY1

    -----------------------------------------------------------
    Rob Williams - Technical Specialist @ All Blue Solutions
    Last edited by DB2Rob; 04-21-13 at 15:07. Reason: Fixed link

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    select random between two dates
    .i.e within a month, within a quarter..
    also it needs to select date between Monday thru Friday...
    I couldn't understand your requirements enough.

    One of my interpretation was...
    to select randomly a day(or some days?) between Monday thru Friday
    in every (quarer and) month between specified two dates.

    For example:
    If two dates were specified as '2012-11-15' and '2013-04-01',
    the required results might be like this...
    Code:
    quarer_month selected_day day_of_the_week
    ------------ ------------ ---------------
    4Q 2012, Nov 2012-11-07   Wed
    4Q 2012, Dec 2012-12-25   Tue
    1Q 2013, Jan 2013-01-28   Mon
    1Q 2013, Feb 2013-02-01   Fri
    1Q 2013, Mar 2013-03-25   Mon
    2Q 2013, Apr 2013-04-11   Thu
    Note1: I took one day for every month.
    Note2: I ignored day of month of specified daets(e.g. took days between '2012-11-01'/*15*/ and '2013-04-30'/*01*/).


    I afraid there were some misunderstandings in my interpretation.
    Please publish your required results for two dates '2012-11-15' and '2013-04-01'.
    Code:
    quarer_month selected_day day_of_the_week
    ------------ ------------ ---------------
    4Q 2012, Oct
    4Q 2012, Nov
    4Q 2012, Dec
    1Q 2013, Jan
    1Q 2013, Feb
    1Q 2013, Mar
    2Q 2013, Apr
    2Q 2013, May
    2Q 2013, Jun
    Add or remove some rows and fill the columns selected_day and day_of_the_week.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •