Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

How can I separate out the Day, Month, Year and Time in a DATETIME datatype?

How can I separate out the Day, Month, Year and Time in a DATETIME datatype?

Problem:

How can I separate out the Day, Month, Year and Time in a DATETIME datatype?

Resolution:

QUESTION
----------------------------------

How can I separate out the Day, Month, Year and Time in a DATETIME datatype?

ANSWER
----------------------------------

First of all you will need to convert the DATETIME datatype to a STRING. See Resolution 20807.

Then when the DATETIME datatype has been converted to a STRING datatype - do the following:

[ ] string  sDate = ([string]dtDate)
    [ ] string  sDay = (GetField (sDate , "-", 3))
    [ ] string  sMonth = (GetField (sDate , "-", 2))
    [ ] string  sYear = (GetField (sDate , "-", 1))
    [ ] string  sTime = (GetField (sDate , " ", 2))
    [ ] sDay = Stuff (sDay, 3, Len(sDay)-2, "")
    [ ] 
    [ ] // now these are all in string variable form that you can work with    [ ] 
    [ ] print ("Day   = {sDay}")
    [ ] print ("Month = {sMonth}")
    [ ] print ("Year  = {sYear}")
    [ ] print ("Time  = {sTime}")


Then we need to combine it back together in one whole string and convert back to DATETIME.

[ ] sDate = ("{sYear}-{sMonth}-{sDay} {sTime}")


Then we convert it back to a DATETIME. If this is not done correctly you will get an error saying incompatible types (See Resolution 20807)

Old KB# 21315

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2013-02-15 19:19
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.