How to access Environment variables from within C# code?

morpheus93

Client
Joined
Jan 25, 2012
Messages
1,068
Reaction score
257
Points
83
Hi,

I know that within a C# code block I can access project variables with project.Variables["myvarname"].Value.

But how can I access an environment variable (variables window in PM, "environment" tab) like e.g. "TimeNow.Date" or "Profile.xxx", "Project.xxx", "Environment.TickCount" and so on?

Thank you.
 
  • Thank you
Reactions: Pierre Paul Jacques

EtaLasquera

Client
Joined
Jan 2, 2017
Messages
527
Reaction score
113
Points
43
project.Profile.WhatYouWant

Tick count and timenow idk.
 

morpheus93

Client
Joined
Jan 25, 2012
Messages
1,068
Reaction score
257
Points
83
@VladZen
Support please help, how can we access environment variables like "TimeNow.Date" from within C# code?
 

EtaLasquera

Client
Joined
Jan 2, 2017
Messages
527
Reaction score
113
Points
43
On C# you can use TimeNow();

Code:
var lst = project.Lists["List1"];
lst.Add(DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss:fff")); //day/month/year hour:minute:second:milesecond
lst.Add(DateTime.Now.ToLongTimeString()); // time only hour:minute:second
lst.Add(DateTime.Now.ToLongDateString()); // formated date time
lst.Add(DateTime.Now.ToShortDateString());// return today
lst.Add(DateTime.Now.ToShortTimeString());// return hour and minute
lst.Add(DateTime.Now.ToString("dd"));//return day
lst.Add(DateTime.Now.ToString("MM"));//return month
lst.Add(DateTime.Now.ToString("yyyy"));//return year
lst.Add(DateTime.Now.ToString("hh"));//return hour
lst.Add(DateTime.Now.ToString("mm"));//return minute
lst.Add(DateTime.Now.ToString("ss"));//return second
lst.Add(DateTime.Now.ToString("ffff"));//return milesecond
 
  • Thank you
Reactions: morpheus93

morpheus93

Client
Joined
Jan 25, 2012
Messages
1,068
Reaction score
257
Points
83
Thanks EtaLasquera, finally I did it in the C# way you described :-)
 

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)