Skip to Content
avatar image
Former Member

UDF to increment date

Hi,

I have a incoming date of format YYYY:MM:DD-HH:MM:SS

We need to increment the time by 10 minutes. Can anyone help me with the UDF.

TIA

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 15, 2013 at 11:57 AM

    Hi Kiran,

    YYYY:MM:DD-HH:MM:SS is not standard date format . I assume that format is "yyyy-MM-dd HH:mm:ss".

    Very simple to increment minutes  by 10 from UDF .

    In function, make argument as string .Use the code below  and return the value .

    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    Date date = new Date  () ;

    try

    {

    date = ( Date )formatter.parse(var1);

    }

    catch ( ParseException  e){}

    Calendar clndr = Calendar.getInstance();

    clndr.setTime(date);

    clndr.add(clndr.MINUTE, 10);

    date = clndr.getTime();

    String strDate = formatter.format(date);

    return strDate;

    This will complete your requirement .

    thanks and regards,

    Anup Banerjee

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 15, 2013 at 09:04 AM

    Hi,

    Use the below logic.Fine tune it as per your req.

    import java.util.Calendar;

    Date Inputtime

    Calendar calendar = Calendar.getInstance();
       calendar.setTime(Inputtime);
       calendar.add(Calendar.MINUTE, 10);
       Inputtime = calendar.getTime();


    Regrads

    Venkat

    Add comment
    10|10000 characters needed characters exceeded