C# add time to actual end field

ATTENTION: This forum is no longer active. Please navigate to our new support site at https://support.starfishetl.com/
Viewing 8 posts (of 8 total)
wondshif
User - Author
Post count: 1
#1

HI, I used the following code to add the DURATIONINMINUTES which is in min. to the ACTIVITYDATETIME field after converting it to PST using C# script, but didn't get the actual result. any idea?

  1. object ScriptedField() { 
  2. DateTime timeUtc = DateTime.Parse(Starfish.OriginData[ACTIVITYDATETIME].ToString());
  3.  
  4. TimeZoneInfo pstZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); 
  5.  
  6. DateTime pstTime = TimeZoneInfo.ConvertTime(timeUtc, pstZone,TimeZoneInfo.Local); 
  7. DateTime myDateTime = DateTime.Parse(pstTime); 
  8.  
  9. myDateTime = myDateTime.AddMinutes(Starfish.OriginData[DURATIONINMINUTES]);
  10.  
  11. return myDateTime; 
  12. }

Thanks,

Comments (8)

Aron Hoekstra's picture Aron Hoekstra
Administrator
Post count: 2
#2

If you do a preview, what is the result in the window for that field?

Depending on your destination, you may need to do a format on the Date.. (usually like yyyy-MM-dd HH:mm:ss)

-Aron

Log in to post comments
wondshif's picture wondshif
User - Author
Post count: 1
#3

Thanks! Aron, The actual start date is converted to PST correctly but the actual end data is blank I am not sure what is wrong in my code.

Log in to post comments
Aron Hoekstra's picture Aron Hoekstra
Administrator
Post count: 2
#4

Maybe I can help debug on my end - can you give me the value of the data for ACTIVITYDATETIME and DURATIONINMINUTES for the source row you're testing with?

Log in to post comments
wondshif's picture wondshif
User - Author
Post count: 1
#5

Please find the attached sreenshot for the sample data. Thanks ActivityDateTime 3/4/2009 DurationInMinutes 60 ActivityDateTime 2/27/2009 DurationInMinutes 30

Attachment: 
Image icon Capture1.JPG, Image icon Capture1_2012-08-28.JPG
Log in to post comments
Aron Hoekstra's picture Aron Hoekstra
Administrator
Post count: 2
#6

Could you please do a screenshot of this data as appears in the Preview tab in Starfish? Thanks

Log in to post comments
wondshif's picture wondshif
User - Author
Post count: 1
#7

here are the two screenshots

Attachment: 
Image icon 2.JPG, Image icon app1.JPG
Log in to post comments
Aron Hoekstra's picture Aron Hoekstra
Administrator
Post count: 2
#8

I think you're really close...

Roslyn.Compilers.CompilationErrorException: (7,40):

is telling you the compile error is in your script on line 7.

There you're doing:
DateTime myDateTime = DateTime.Parse(pstTime);

but pstTime is already a DateTime object, so you could just set myDateTime = pstTime directly..

You may also run into a Double conversion error.. your line 9 should do a Double cast like this..

myDateTime = myDateTime.AddMinutes(Double.Parse(Starfish.OriginData[DURATIONINMINUTES].ToString()));

Here's the complete code:
object ScriptedField() {
DateTime timeUtc = DateTime.Parse(Starfish.OriginData[ACTIVITYDATETIME].ToString());

TimeZoneInfo pstZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

DateTime pstTime = TimeZoneInfo.ConvertTime(timeUtc, pstZone,TimeZoneInfo.Local);
DateTime myDateTime = pstTime;

myDateTime = myDateTime.AddMinutes(Double.Parse(Starfish.OriginData[DURATIONINMINUTES].ToString()));

return myDateTime;
}

Log in to post comments
wondshif's picture wondshif
User - Author
Post count: 1
#9

Thank you Aron it worked

Log in to post comments
Viewing 8 posts (of 8 total)

Forum Login

Login or sign up for our forums to connect to the user community.

Reply

You must log in to post.

Not a Member? Register.