单个数字到年份的高级转换,以及连字符 [英] Advanced conversion of a single number to year, along with hyphen

查看:14
本文介绍了单个数字到年份的高级转换,以及连字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在水晶报表中将字符串值转换为日期时间

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

日期格式是

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

我想要的输出是

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!

推荐答案

创建一个新公式并应用下面的代码.{Command.mydate} 将替换为您的字段

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

这篇关于单个数字到年份的高级转换,以及连字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆