Replace the Cubersome date2str
Hello everyone!
Thought I would share a good little piece of code that I have found so very useful. If anyone of you has ever wanted to convert a give Date variable to a string, you have came across a method called Date2Str().
This method is just so wacko to me. I have create a Static method in the global class so it can be called from anywhere, that takes care of changing your passed in Date variable to a string for you! (American Standard Date that is)
This Little piece of code has saved me a lot of typing over and over again. I hope that someone else can get the same use out of it!
(Edit: 10.25.2005)
I had two comments posted on this entry, that are valid and great! The first was asking about the SQLstr() method. This is a Static method that I created that also lives in the Global class. It adds single tick marks around a passed in string which helps when working with ODBC datasources within Axapta.
There was another comment posted by Steen Andersen (who is releasing an Axapta book soon!) That asked the question why not use: date2strUsr(). To be honest I had never heard of this method, and turns out it does what my above custom method does, plus it makes sure to return the date in the logged in users local setting is for. So needless to say that I would recommend using the built in function date2strUser() over date2str(), unless you had a specific need for converting a date to a specific string based format.
(Thanks Steen!)
Find a job at: www.DynamicsAXJobs.com
Thought I would share a good little piece of code that I have found so very useful. If anyone of you has ever wanted to convert a give Date variable to a string, you have came across a method called Date2Str().
This method is just so wacko to me. I have create a Static method in the global class so it can be called from anywhere, that takes care of changing your passed in Date variable to a string for you! (American Standard Date that is)
public static str safeDateStr(Date _d, boolean
AddTicks=false){ str _s;
;
_s = _s + date2str(_d,213,2,2,2,2,4);
if(AddTicks) { _s = SQLstr(_s); }
return _s;}
This Little piece of code has saved me a lot of typing over and over again. I hope that someone else can get the same use out of it!
(Edit: 10.25.2005)
I had two comments posted on this entry, that are valid and great! The first was asking about the SQLstr() method. This is a Static method that I created that also lives in the Global class. It adds single tick marks around a passed in string which helps when working with ODBC datasources within Axapta.
There was another comment posted by Steen Andersen (who is releasing an Axapta book soon!) That asked the question why not use: date2strUsr(). To be honest I had never heard of this method, and turns out it does what my above custom method does, plus it makes sure to return the date in the logged in users local setting is for. So needless to say that I would recommend using the built in function date2strUser() over date2str(), unless you had a specific need for converting a date to a specific string based format.
(Thanks Steen!)
Find a job at: www.DynamicsAXJobs.com
6 Comments:
Hi, Brandon,
I was trying to find SQLstr function in global and kernel function with no luck. I suppose you have another global function that should be included for the use of this function, or is it Axapta 4.0? :)
Btw, good idea for the safeDateStr function.
What about using the global method date2StrUsr() - it will convert a date to the users default date format.
- Good luck with your blog, Brandon.
Thanks guys for the comments! I have updated the post. Thanks Steen for the good luck, same to you on the new book!
How I can find the detailed info for Date2strUsr() function?. Just want to uncover these kind of functions....
your axapta mate,
subbu
gound it in global class.
thanks nayway.
another way to do it , is to user -1 for all the parameters after the 123 or 322 , in that way ax takes the windows client settings
Post a Comment
<< Home