Dynamics AX
  RSS Feed  LinkedIn  Twitter
Want to turn you're data into a true asset? Ready to break free from the report factory?
Ready to gain true insights that are action focused for truly data informed decisions?
Want to do all of this across mutliple companies, instances of Dynamics and your other investments?
Hillstar Business Intelligence is the answer then! (www.HillstarBI.com)

Hillstar Business Intelligence for Microsoft Dynamics AX and NAV on Mobile, Desktop, Tablet


Let us prove to you how we can take the complexity out of the schema and truly enable users to answer the needed questions to run your business! Visit Hillstar Business Solutions at: www.HillstarBI.com

Monday, October 24, 2005

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)

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:

Anonymous Anonymous said...

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.

8:06 PM  
Anonymous Anonymous said...

What about using the global method date2StrUsr() - it will convert a date to the users default date format.

- Good luck with your blog, Brandon.

5:00 AM  
Blogger brandon said...

Thanks guys for the comments! I have updated the post. Thanks Steen for the good luck, same to you on the new book!

8:23 AM  
Anonymous Anonymous said...

How I can find the detailed info for Date2strUsr() function?. Just want to uncover these kind of functions....

your axapta mate,
subbu

3:54 PM  
Anonymous Anonymous said...

gound it in global class.
thanks nayway.

4:04 PM  
Blogger Unknown said...

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

6:51 AM  

Post a Comment

<< Home


Copyright 2005-2011, J. Brandon George - All rights Reserved