Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Add question

Login

Register Now

APPSeCONNECT community provides a new way for integration super heros connect the external world. Join hands together to build a community of people to help each other, solve problems or share knowledge.

How to format date – time

How to format date – time

During transformation of data between source and destination, the formatting of the data sometimes becomes crucial. The data transformation logic requires data to be perfectly compatible with the destination application such that things are correctly transformed and pushed to the target application. For instance, if your source has a date format of say ‘yyyy/MM/dd’ while your target application requires it to be different, you need your transformation to be compatible with the target application.

As an implementer, you need to ensure the data is correctly transformed to the data which your target application understands. To do such scenario, you need to do mapping of the source field to be wrapped around a function such that it transforms the data to a correct format.

Understanding Date time Format

Datetime data is a complex primitive data type which contains multiple integer to indicate different values. Let us understand the format specifier options for a datetime field.

d – Represents the day of a particular date. For instance, if you use d to indicate 3rd day of a month, the value it will produce is 3.

dd – Represents mandatory 2 digit value of day of a particular date. If you specify dd  for 3rd day of a month, it will be represented as 03.

ddd – Represents the abbreviated name of the day of week. Result would be Mon, Tue etc.

dddd – Represents the full name of the date in a week. Result would be Monday, Tuesday etc.

m – Represents minutes of a particular datetime. 0 through 59 is valid values.

mm – Two digit representation of minute in a datetime. 00 through 59 are valid values.

M – Represents month of a particular date. 1 – 12 is valid here.

MM – Represents two digit representation of month. 01 – 12 is valid values.

MMM – Abbreviation version of month. Eg, Jan, Feb, Mar etc.

MMMM – Represents full name of the month. Eg. January, February, March etc.

y – The year, 0 to 99.

yy – The year, 00 to 99.

yyy – This is the year in 3 digit. 001, 900, 1900 etc.

yyyy – This is the year in four digit.  0001, 0900, 1900 etc.

t – First character of AM/PM designator. For instance, P is for PM.

tt – The AM/PM designator.

h, hh – Hour representation in 12 hour clock.

H, HH – Represents the 24 hour representation of hour in a clock.

s – Represents the second.

ss – Represents the two digit representation of second.

K – Specifies the timezone information.

 

These parameters could be directly used inside a mapping section of a transformation. You can use the generic function FormatDate to reformat the values passed to the transformer.

format datetime

The image shows how you can map the Timestamp attribute of target xml schema by getting date value of CreatedDate on Source schema and formatting it into a specific format. You can use any of the format specified in the string to indicate a particular formatted output.

Please note there are two formats string specifier present in the format section. The 2nd format string specifier will indicate the source datetime format, while the 3rd parameter will indicate the resultant datetime format string.

Some common formats

Here in all the days, I will use the format string for a date October 1st, 2019 at 04:10.29.299pm

MMddyyyy – 10012019

MM/dd/yyyy – 10/01/2019

MM-dd-yyyy – 10-01-2019

yyyyMMdd HHmmss – 20191001 161029

yyyy-MM-dd’T’HH:mm:ss.SSSZZ – 2019-10-01T16:10:29.299 – 05:00

 

Similar to the above examples, you can create any date format string based on the requirements you need.

Also Check out: Working with DateTime

About Abhishek SurVerifiedBeginner

VP, Products at InSync Abhishek Sur has been a Microsoft MVP since 2011. He is currently working as a Product Head with Insync Tech-Fin Solutions Pvt Ltd. He has profound theoretical insight and years of hands-on experience in different .NET products and languages. Over the years, he has helped developers throughout the world with his experience and knowledge. He owns a Microsoft User Group in Kolkata named Kolkata Geeks and regularly organizes events and seminars in various places to spread .NET awareness. A renowned public speaker, voracious reader, and technology buff, Abhishek's main interest lies in exploring the new realms of .NET technology and coming up with priceless write-ups on the unexplored domains of .NET. He is associated with Microsoft's Insider list on WPF and C# and stays in touch with Product Group teams. He holds a Master's degree in Computer Application along with various other certificates to his credit. Abhishek is a freelance content producer, developer, and site administrator. His website www.abhisheksur.com guides both budding and experienced developers in understanding the details of languages and latest technologies. He has a huge fan following on social networks. You can reach him at books@abhisheksur.com, get online updates from his Facebook account, or follow him on Twitter @abhi2434.

Follow Me

Comments ( 2 )

  1. […] This mapping will just get the current datetime or current Universal datetime and reformat the data using a format specifier. […]

Leave a reply

Share via
Copy link
Powered by Social Snap