on 04-05-2013 11:17 AM
We have to convert a delivery schedule code to a delivery date. schedule code is a 3 digit number.
The delivery schedule is a 3 digit number - see below:
100-199 Monday
200-299 Tuesday
300-399 Wednesday
400-499 Thursday
500-599 Friday
600-699 Saturday
700-799 Sunday
If current date is 5th-Apr and the input delivery schedule codes are
126 then delivery date 8th-Apr
218 then delivery date 9th-Apr
Can anyone please guide on the above requirement?
Regards,
Malini
Hi Malini,
You can try following also
Here I am send Delivery Schedule as employee number and current date with following format:
and use following UDF
______________________________________________
try
{
int curDayNumber = 0;
int ds = Integer.parseInt(ds1);
int dayNumber=0,addDay;
String DSday="";
String finalDate="";
if(CDate.equals("Mon"))
curDayNumber=1;
else if(CDate.equals("Tue"))
curDayNumber=2;
else if(CDate.equals("Wed"))
curDayNumber=3;
else if(CDate.equals("Thu"))
curDayNumber=4;
else if(CDate.equals("Fri"))
curDayNumber=5;
else if(CDate.equals("Sat"))
curDayNumber=6;
else if(CDate.equals("Sun"))
curDayNumber=7;
if ( ds > 99 && ds< 200)
{
dayNumber = 1;
DSday = "Mon";
}
else if ( ds > 199 && ds< 300)
{
DSday = "Tue";
dayNumber = 2;
}
else if ( ds > 299 && ds< 400)
{
DSday = "Wed";
dayNumber = 3;
}
else if ( ds > 399 && ds< 500)
{
DSday = "Thu";
dayNumber = 4;
}
else if ( ds > 499 && ds< 600)
{
DSday = "Fri";
dayNumber = 5;
}
else if ( ds > 599 && ds< 700)
{
DSday = "Sat";
dayNumber = 6;
}
else if ( ds > 699 && ds< 800)
{
DSday = "Sun";
dayNumber = 7;
}
if (dayNumber <= curDayNumber)
dayNumber = dayNumber+7;
addDay = dayNumber-curDayNumber;
SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
Calendar cal = Calendar.getInstance();
cal.add( Calendar.DATE, addDay );
finalDate=dateFormat.format(cal.getTime());
return finalDate;
}
catch(Exception pE)
{
//return "error";
return pE.toString() ;
}
____________________________________________________
Regards
Gagan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Anupam and Gagandeep for your efforts.
I have arrived at the answer. I have used the below udf. I took the first digit of the 3 digit schedule code as input.
public String deriveDeliveryDate(int inputDay, Container container) throws StreamTransformationException
{
int weekDays[] = {7,1,2,3,4,5,6};
int difference;
//getting the current day of the week
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DAY_OF_WEEK);
//Converting the standard calendar as per delivery schedule
int targetDay = weekDays[day-1];
if(inputDay > targetDay)
{
difference = inputDay - targetDay;
}
else if(inputDay == targetDay)
difference = 0;
else
difference = (7 - targetDay ) + inputDay;
calendar.add(Calendar.DATE,difference);
String strdate = null;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
strdate = sdf.format(calendar.getTime());
return strdate;
}
Hi Malini,
Please try this UDF. Hope this resolves the problem.
public static String deliveryDate(String code)
{
String delDate="";
String dow[]={"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
int dowi[]={0,1,2,3,4,5,6};
java.text.DateFormat dateFormat = new java.text.SimpleDateFormat("dd-MMM");
java.util.Date date = new java.util.Date();
String s=dateFormat.format(date);
int scheduleCode=new Integer(code).intValue();
java.text.DateFormat dateFormat1=new java.text.SimpleDateFormat("E");
s=dateFormat1.format(date);
int i=0;
for(i=0;i<dow.length;++i)
{
if(s.equalsIgnoreCase(dow[i]))
{
break;
}
}
int j=i;
int d=(scheduleCode/100)-1;
int c=0;
for(i=j;i!=d;)
{
c++;
i=(i+1)%7;
}
java.util.Calendar cal = java.util.Calendar.getInstance();
cal.add(java.util.Calendar.DATE,c);
delDate=dateFormat.format(cal.getTime());
return delDate;
}
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Malini,
Is your requirement is to get weekday name based on 3 digit delivery code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Could you please explain the dependency of delivery date on current date & delivery code..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Can you elaborate your codes and dates required?
Regards,
Sreeni.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.