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

前端 未结 1 1034
囚心锁ツ
囚心锁ツ 2021-01-16 23:05

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)-         


        
1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 23:28

    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
    

    0 讨论(0)
提交回复
热议问题