Thursday, May 20, 2010

To Get the Local/Current PC DateTime not the Server Time using Peoplecode

two ways we can achieve this

1. Using Personalization

%ClientDate:

%ClientDate returns the current date for the current user, adjusted for the user’s time zone. This is the date as specified with the current user's personalizations.You can use this system variable as the default constant for a date field.This is potentially one day different than the server date, which is returned with %Date.

Let's say, the Server is located in US, the business users spread across Global Other than US.

So, if we issue %Date (or any other Date variables) it will return server time.

Suppose if the bussiness user located in India, he should get Date time in IST.



2.Using  DateTimeToTimeZone
 syntax
DateTimeToTimeZone(OldDateTime, SourceTimeZone, DestinationTimeZone)
 
Use the DateTimeToTimeZone function to convert datetimes from the datetime specified by SourceTimeZone to the datetime specified by DestinationTimeZone.

to know the client zone use the variable:- %ClientTimeZone

Eg:- DateTimeToTimeZone(%Datetime, "UST", "IST")
 this will convert US date time to Indian Std Date time.
 
Refer to:-
PeopleBooks: PeopleCode Language Reference 
:-)

No comments: