Advanced conversion of a single number to year, along with hyphen

早过忘川 提交于 2019-12-30 14:50:47

问题


I want to convert the string value to datetime in crystal report

date format are

05-10-7-AAAA (mm-dd-year(2017)-AAAA)
05-23-3-00   (mm-dd-year(2013)-00)
...

My desired output is

10-May-2017
23-May-2013
...

My good reference has been How to convert string value to proper datetime format & the following attempts threw me errors:

Date({ORDERCHECKVIEW.LOTNUMBER}[4 to 5], ***{ORDERCHECKVIEW.LOTNUMBER}[1 to 2], {ORDERCHECKVIEW.LOTNUMBER}[7]***)  //Too many arguments have been given to this function

&

DateValue({ORDERCHECKVIEW.LOTNUMBER})  //Bad date format string

Thank you so much in advance and I will be as responsive as I can!


回答1:


Create a new Formula and apply the code below. {Command.mydate} will be replaced with your field

local StringVar mDate;
local StringVar mMonth;
local StringVar mDay;
local StringVar mYear;
//local StringVar mSuffix:= StrReverse(left(StrReverse({Command.mydate}),instr(StrReverse({Command.mydate}),"-",1)-1));    // to get suffix

mDate:= left({Command.mydate},InStrRev ({Command.mydate},"-" )-1);     // get dd
mMonth:= left(mDate,2);  // get MM
mDay := Mid (mDate,4 ,2 );  // get YYYY
mYear := totext(2010 + CDbl (right(mDate,InStr(StrReverse(left({Command.mydate},InStrRev ({Command.mydate},"-" )-1)),"-") -1 )),0,""); // transform   2017

cDate(cDbl(mYear),cDbl(mMonth),cDbl(mDay));   // this will display dd-MM-YYYY     may not display as 01 for dd but you can always customise this in the GUI the important point is this is now a date field


来源:https://stackoverflow.com/questions/44143964/advanced-conversion-of-a-single-number-to-year-along-with-hyphen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!