Lasso Soft Inc. > Home

[mv_clcdat]

Linkmv_clcdat
AuthorMarc Vos
CategoryDate
Version8.x
LicensePublic Domain
Posted03 Aug 2009
Updated19 Mar 2012
More by this author...

Description

This tag is for handling dates entered by users, showing dates to users and do some date calculations, like leapyear, last day of month, difference in days, hours, minutes. etc. Here are some examples of what it can do for you (left of the colon is the fed date, right side is the result):

Action = FS
31082005 : 20050831
08312005 : 0
9082005 : 20050809
9.8.2005 : 20050809
9/8/2005 : 20050809
090805 : 20050809
90805 : 20050809
9.8.05 : 20050809
9/8/05 : 20050809
9-8-2005 : 20050809
9-8-05 : 20050809
zero : 0
nothing : 0


Action = FSD
31082005 : 20050831
08312005 : 0
908205 : 0
9.0.2005 : 20050309
0/8/2005 : 20050819
000805 : 20050819
90005 : 20050309
9.8.05 : 00050809
9/8/05 : 20050809
9-8-00 : 20120809
9-0-00 : 20120309
zero : 20120319
nothing : 0


Action = TS
20051223 : 23-12-2005
2005-12-23 : 23-12-2005
2005.12.23 : 23-12-2005
2005/12/23 : 23-12-2005
nul :
niks :


Action = EX
20051223 : 20051223
2005-12-23 : 20051223
2005.12.23 : 20051223
2005/12/23 : 20051223
51223 : 20051223
5/12/23 : 20051223
nul : 0
niks : 0


Action = LY
1996 : 29
19971200 : 28
19981223 : 28
1999-12-23 : 28
2000.12.23 : 29
2001/12/23 : 28
21223 : 28
3/12/23 : 28
4-12-23 : 29
nul : 0
niks : 0


Action = LD
20040223 : 20040229
2004-03-23 : 20040331
2004.04.23 : 20040430
2004/05/23 : 20040531
40623 : 20040630
4/07/23 : 20040731
nul : 0
niks : 0


Action = **
Today : 20120319

Action = **S
Today : 20120319112129


Action = DF
2004-02-12 08:00:00 - 2004-02-25 21:30:00 : array: (13), (13), (30), (00)
2004-02-25 21:30:00 - 2004-02-12 08:00:00 : array: (-13), (-13), (-30), (-0)
2000-01-01 21:30:00 - 2000-01-01 08:00:00 : array: (-0), (-13), (-30), (-0)
2000-01-01 21:30:00 - 2000-01-01 22:11:00 : array: (0), (00), (41), (00)


Action = AD & SD
2004-02-12 08:00:00 + 1 day, 20 minutes : 20040213
2004-02-25 21:30:00 - 1 day, 20 minutes : 20040224
2000-01-01 21:30:00 + 1 month, 1 week, 10 minutes : 20000208
2000-01-01 21:30:00 - 1 month, 1 week, 10 minutes : 19991125
mv_clcdat(-action='**') - 130 days : 20111110
mv_clcdat(-action='**') - 45 days (ttt-cleanup) : 20120203
mv_clcdat(-action='**') - 15 days (ttt-cleanup) : 20120304

Action = ADS & SDS
2004-02-12 08:00:00 + 1 day, 20 minutes : 20040213082000
2004-02-25 21:30:00 - 1 day, 20 minutes : 20040224211000
2000-01-01 21:30:00 + 1 month, 1 week, 10 minutes : 20000208214000
2000-01-01 21:30:00 - 1 month, 1 week, 10 minutes : 19991125212000
mv_clcdat(-action='**S') - 2 hours (ttt-pdf-export-script) : 20120319092129
mv_clcdat(-action='**S') - 20 days (ttt-pdf-export-script) : 20120228112129


Action = SP
2001-01 : array: (0020), (01), (01), (00), (00), (00)
2001-01-01 : array: (2001), (01), (01), (00), (00), (00)
2002-02-02 02 : array: (2002), (02), (02), (02), (00), (00)
2003-03-03 03:03 : array: (2003), (03), (03), (03), (03), (00)
2004-04-04 04:04:04 : array: (2004), (04), (04), (04), (04), (04)
20050505050505 : array: (2005), (05), (05), (05), (05), (05)
200606060606 : array: (2006), (06), (06), (06), (06), (00)
2007070707 : array: (2007), (07), (07), (07), (00), (00)
20080808 : array: (2008), (08), (08), (00), (00), (00)
200909 : array: (0020), (09), (09), (00), (00), (00)


Action = WM
2001-01 : 2001001
01-02 : 2001008
200202 : 2002007
03 : 2012016
53 : 2011361

Action = WMD
2001-01 : 20010101
01-02 : 20010108
200202 : 20020107
03 : 20120116
53 : 20111226

Sample Usage

Action = FS
31082005 : [mv_clcdat(-date1='31082005', -date2='0', -action='FS')]
08312005 : [mv_clcdat(-date1='08312005', -date2='0', -action='FS')]
9082005 : [mv_clcdat(-date1='9082005', -date2='0', -action='FS')]
9.8.2005 : [mv_clcdat(-date1='9.8.2005', -date2='0', -action='FS')]
9/8/2005 : [mv_clcdat(-date1='9/8/2005', -date2='0', -action='FS')]
090805 : [mv_clcdat(-date1='090805', -date2='0', -action='FS')]
90805 : [mv_clcdat(-date1='90805', -date2='0', -action='FS')]
9.8.05 : [mv_clcdat(-date1='9.8.05', -date2='0', -action='FS')]
9/8/05 : [mv_clcdat(-date1='9/8/05', -date2='0', -action='FS')]
9-8-2005 : [mv_clcdat(-date1='9-8-2005', -date2='0', -action='FS')]
9-8-05 : [mv_clcdat(-date1='9-8-05', -date2='0', -action='FS')]
nul : [mv_clcdat(-date1='0', -date2='0', -action='FS')]
niks : [mv_clcdat(-date1='', -date2='0', -action='FS')]

 

Action = FSD
31082005 : [mv_clcdat(-date1='31082005', -date2='0', -action='FSD')]
08312005 : [mv_clcdat(-date1='08312005', -date2='0', -action='FSD')]
908205 : [mv_clcdat(-date1='908205', -date2='0', -action='FSD')]
9.0.2005 : [mv_clcdat(-date1='9.0.2005', -date2='0', -action='FSD')]
0/8/2005 : [mv_clcdat(-date1='0/8/2005', -date2='0', -action='FSD')]
000805 : [mv_clcdat(-date1='000805', -date2='0', -action='FSD')]
90005 : [mv_clcdat(-date1='90005', -date2='0', -action='FSD')]
9.8.05 : [mv_clcdat(-date1='9.8.0005', -date2='0', -action='FSD')]
9/8/05 : [mv_clcdat(-date1='9/8/05', -date2='0', -action='FSD')]
9-8-00 : [mv_clcdat(-date1='9-8-00', -date2='0', -action='FSD')]
9-0-00 : [mv_clcdat(-date1='9-0-00', -date2='0', -action='FSD')]
nul : [mv_clcdat(-date1='0', -date2='0', -action='FSD')]
niks : [mv_clcdat(-date1='', -date2='0', -action='FSD')]

 

Action = TS
20051223 : [mv_clcdat(-date1='20051223', -date2='0', -action='TS')]
2005-12-23 : [mv_clcdat(-date1='2005-12-23', -date2='0', -action='TS')]
2005.12.23 : [mv_clcdat(-date1='2005.12.23', -date2='0', -action='TS')]
2005/12/23 : [mv_clcdat(-date1='2005/12/23', -date2='0', -action='TS')]
nul : [mv_clcdat(-date1='0', -date2='0', -action='TS')]
niks : [mv_clcdat(-date1='', -date2='0', -action='TS')]

 

Action = EX
20051223 : [mv_clcdat(-date1='20051223', -date2='0', -action='EX')]
2005-12-23 : [mv_clcdat(-date1='2005-12-23', -date2='0', -action='EX')]
2005.12.23 : [mv_clcdat(-date1='2005.12.23', -date2='0', -action='EX')]
2005/12/23 : [mv_clcdat(-date1='2005/12/23', -date2='0', -action='EX')]
51223 : [mv_clcdat(-date1='51223', -date2='0', -action='EX')]
5/12/23 : [mv_clcdat(-date1='5/12/23', -date2='0', -action='EX')]
nul : [mv_clcdat(-date1='0', -date2='0', -action='EX')]
niks : [mv_clcdat(-date1='', -date2='0', -action='EX')]

 

Action = LY
1996 : [mv_clcdat(-date1='1996', -date2='0', -action='LY')]
19971200 : [mv_clcdat(-date1='19971200', -date2='0', -action='LY')]
19981223 : [mv_clcdat(-date1='19981223', -date2='0', -action='LY')]
1999-12-23 : [mv_clcdat(-date1='1999-12-23', -date2='0', -action='LY')]
2000.12.23 : [mv_clcdat(-date1='2000.12.23', -date2='0', -action='LY')]
2001/12/23 : [mv_clcdat(-date1='2001/12/23', -date2='0', -action='LY')]
21223 : [mv_clcdat(-date1='21223', -date2='0', -action='LY')]
3/12/23 : [mv_clcdat(-date1='3/12/23', -date2='0', -action='LY')]
4-12-23 : [mv_clcdat(-date1='4-12-23', -date2='0', -action='LY')]
nul : [mv_clcdat(-date1='0', -date2='0', -action='LY')]
niks : [mv_clcdat(-date1='', -date2='0', -action='LY')]

 

Action = LD
20040223 : [mv_clcdat(-date1='20040223', -date2='0', -action='LD')]
2004-03-23 : [mv_clcdat(-date1='2004-03-23', -date2='0', -action='LD')]
2004.04.23 : [mv_clcdat(-date1='2004.04.23', -date2='0', -action='LD')]
2004/05/23 : [mv_clcdat(-date1='2004/05/23', -date2='0', -action='LD')]
40623 : [mv_clcdat(-date1='40623', -date2='0', -action='LD')]
4/07/23 : [mv_clcdat(-date1='4/07/23', -date2='0', -action='LD')]
nul : [mv_clcdat(-date1='0', -date2='0', -action='LD')]
niks : [mv_clcdat(-date1='', -date2='0', -action='LD')]

 

Action = **
Today : [mv_clcdat(-action='**')]

Action = **S
Today : [mv_clcdat(-action='**S')]

 

Action = DF
2004-02-12 08:00:00 - 2004-02-25 21:30:00 : [mv_clcdat(-date1='2004-02-12 08:00:00', -date2='2004-02-25 21:30:00', -action='DF')]
2004-02-25 21:30:00 - 2004-02-12 08:00:00 : [mv_clcdat(-date1='2004-02-25 21:30:00', -date2='2004-02-12 08:00:00', -action='DF')]
2000-01-01 21:30:00 - 2000-01-01 08:00:00 : [mv_clcdat(-date1='2000-01-01 21:30:00', -date2='2000-01-01 08:00:00', -action='DF')]
2000-01-01 21:30:00 - 2000-01-01 22:11:00 : [mv_clcdat(-date1='2000-01-01 21:30:00', -date2='2000-01-01 22:11:00', -action='DF')]

 

Action = AD & SD
2004-02-12 08:00:00 + 1 day, 20 minutes : [mv_clcdat(-date1='2004-02-12 08:00:00', -action='AD', -day=1, -minute=20)]
2004-02-25 21:30:00 - 1 day, 20 minutes : [mv_clcdat(-date1='2004-02-25 21:30:00', -action='SD', -day=1, -minute=20)]
2000-01-01 21:30:00 + 1 month, 1 week, 10 minutes : [mv_clcdat(-date1='2000-01-01 21:30:00', -action='AD', -month=1, -week=1, -minutes=10)]
2000-01-01 21:30:00 - 1 month, 1 week, 10 minutes : [mv_clcdat(-date1='2000-01-01 21:30:00', -action='SD', -month=1, -week=1, -minutes=10)]
mv_clcdat(-action='**') - 130 days : [mv_clcdat(-date1=mv_clcdat(-action='**'), -action='SD', -days=130)]
mv_clcdat(-action='**') - 45 days (ttt-cleanup) : [mv_clcdat(-date1=mv_clcdat(-action='**'), -action='SD', -days=45)]
mv_clcdat(-action='**') - 15 days (ttt-cleanup) : [mv_clcdat(-date1=mv_clcdat(-action='**'), -action='SD', -days=15)]

Action = ADS & SDS
2004-02-12 08:00:00 + 1 day, 20 minutes : [mv_clcdat(-date1='2004-02-12 08:00:00', -action='ADS', -day=1, -minute=20)]
2004-02-25 21:30:00 - 1 day, 20 minutes : [mv_clcdat(-date1='2004-02-25 21:30:00', -action='SDS', -day=1, -minute=20)]
2000-01-01 21:30:00 + 1 month, 1 week, 10 minutes : [mv_clcdat(-date1='2000-01-01 21:30:00', -action='ADS', -month=1, -week=1, -minutes=10)]
2000-01-01 21:30:00 - 1 month, 1 week, 10 minutes : [mv_clcdat(-date1='2000-01-01 21:30:00', -action='SDS', -month=1, -week=1, -minutes=10)]
mv_clcdat(-action='**S') - 2 hours (ttt-pdf-export-script) : [mv_clcdat(-date1=mv_clcdat(-action='**S'), -action='SDS', -hours=2)]
mv_clcdat(-action='**S') - 20 days (ttt-pdf-export-script) : [mv_clcdat(-date1=mv_clcdat(-action='**S'), -action='SDS', -days=20)]

Action = SP
2001-01 : [mv_clcdat(-date1='2001-01', -action='SP')]
2001-01-01 : [mv_clcdat(-date1='2001-01-01', -action='SP')]
2002-02-02 02 : [mv_clcdat(-date1='2002-02-02 02', -action='SP')]
2003-03-03 03:03 : [mv_clcdat(-date1='2003-03-03 03:03', -action='SP')]
2004-04-04 04:04:04 : [mv_clcdat(-date1='2004-04-04 04:04:04', -action='SP')]
20050505050505 : [mv_clcdat(-date1='20050505050505', -action='SP')]
200606060606 : [mv_clcdat(-date1='200606060606', -action='SP')]
2007070707 : [mv_clcdat(-date1='2007070707', -action='SP')]
20080808 : [mv_clcdat(-date1='20080808', -action='SP')]
200909 : [mv_clcdat(-date1='200909', -action='SP')]

Action = WM
2001-01 : [mv_clcdat(-date1='2001-01', -action='WM')]
01-02 : [mv_clcdat(-date1='01-02', -action='WM')]
200202 : [mv_clcdat(-date1='200202', -action='WM')]
03 : [mv_clcdat(-date1='03', -action='WM')]
53 : [mv_clcdat(-date1='53', -action='WM')]
Action = WMD
2001-01 : [mv_clcdat(-date1='2001-01', -action='WMD')]
01-02 : [mv_clcdat(-date1='01-02', -action='WMD')]
200202 : [mv_clcdat(-date1='200202', -action='WMD')]
03 : [mv_clcdat(-date1='03', -action='WMD')]
53 : [mv_clcdat(-date1='53', -action='WMD')]

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

format('%Y%m%d');		else;			#result = date->format('%Y%m%d%H%M%S');		/if;
	else((#action == 'AD') || (#action == 'ADS') || (#action == 'SD') || (#action == 'SDS')); // !AD, ADS, SD, SDS		// AD = Add days : positive values get added, negative values get subtracted.		// SD = Subtract days : positive values get subtracted, negative values get added.		// In:  DATE1 = a Date YYYY-MM-DD with or without a time HH:MM:SS, separated by a space : "YYYY-MM-DD HH:MM:SS" or		// In:  DATE1 = a Date YYYYMMDD with or without a time HHMMSS, not separated : "YYYYMMDDHHMMSS"		// In:  years/months/weeks/days/hours/minutes/seconds = the times to add (same params as dat_add/-subtract uses).		// Out: YYYYMMDD[HHMMSS] - for HHMMSS use ADS or SDS as -action param.				// If date1 does not contain hhmmss, for correct addition or subtraction, 120000 (mid day) is concatenated to date1		if(#date1->size == 8);			#date1 += '120000';		else(#date1->size == 10);			#date1 += ' 12:00:00';		/if;				if(#action == 'AD');			#result = date_format(date_add(date(#date1), 				-year=#year,				-month=#month,				-week=#week,				-day=#day,				-hour=#hour,				-minute=#minute,				-second=#second				), -format='%Y%m%d');//			#result = '1: ' + #year + '/' + #month + '/' + #week + '/' + #day + '/' + #hour + '/' + #minute + '/' + #second;		else(#action == 'ADS');			#result = date_format(date_add(date(#date1), 				-year=#year,				-month=#month,				-week=#week,				-day=#day,				-hour=#hour,				-minute=#minute,				-second=#second				), -format='%Y%m%d%H%M%S');//			#result = '2: ' + #year + '/' + #month + '/' + #week + '/' + #day + '/' + #hour + '/' + #minute + '/' + #second;		else(#action == 'SD');			#result = date_format(date_subtract(date(#date1), 				-year=#year,				-month=#month,				-week=#week,				-day=#day,				-hour=#hour,				-minute=#minute,				-second=#second				), -format='%Y%m%d');//			#result = '3: ' + #year + '/' + #month + '/' + #week + '/' + #day + '/' + #hour + '/' + #minute + '/' + #second;		else(#action == 'SDS');			#result = date_format(date_subtract(date(#date1), 				-year=#year,				-month=#month,				-week=#week,				-day=#day,				-hour=#hour,				-minute=#minute,				-second=#second				), -format='%Y%m%d%H%M%S');//			#result = '4: ' + #year + '/' + #month + '/' + #week + '/' + #day + '/' + #hour + '/' + #minute + '/' + #second;
		else;			#result = 0;		/if;
	else(#action == 'AN' || #action == 'EX' || #action == 'LD' || #action == 'LY'); // !AN, EX, LD, LY		// AN = Alpha to Numeric		// In:  DATE1 = a Date YYYY-MM-DD with or without a time HH:MM:SS, separated by a space : "YYYY-MM-DD HH:MM:SS"		// Out: YYYYMMDDHHMMSS
		// EX = Export, meant for creating ascii files		// In:  DATE1 = a Date from a database DATE-type field, like yyyy-mm-dd		// Out: YYYYMMDD				// LD = Last day of month		// In:  DATE1 = a Date from a database field, like YYYYMMDD or YYYY-MM-DD or YYYY.MM.DD or YYYY/MM/DD		// Out: YYYYMMDD where DD = 28/29, 30 or 31.
		// LY = Leap year test		// In:  DATE1 = a Date from a database field, like YYYYMMDD or YYYY-MM-DD or YYYY.MM.DD or YYYY/MM/DD		//		  or a year, like YYYY.		// Out: 29 (true) / 28 (false)
		// Get only the numbers		#result = string(string_findregexp(#date1, -find='\\d')->join(''));
		// check the length		if(#result->size <= 4);			#result->padleading(4, '0');			if(integer(#result) != 0);				#result = #result + '0101';			/if;		else(#result->size <= 6);			#result->padleading(6, '0');			if(integer(#result) != 0);				#result = '20' + #result;			/if;		else(#result->size <= 8);			#result->padleading(8, '0');		else(#result->size > 8);			if(#action == 'AN');				#result = #result->substring(1,14);			else;				#result = #result->substring(1,8);			/if;		/if;				if(integer(#result) == 0);			#result = '0';		else((#action == 'LY') || (#action == 'LD'));			#num = integer(#result->substring(1,4));			if(((math_mod(#num, 4) == 0) && (math_mod(#num, 100) != 0)) || (math_mod(#num, 400) == 0));				#tmp = '29';			else;				#tmp = '28';			/if;						if(#action == 'LD');				#myMDAYS->get(2) = #tmp;				#result = #result->substring(1,6) + #myMDAYS->get(integer(#result->substring(5,2)));			else;				#result = #tmp;			/if;		/if;			else((#action == 'FS') || (#action == 'FSD')); // !FS, FSD		// FS = From Screen (FSD = FS + force date)		// In:  DATE1 = a Date entered by a user, like dd/mm/yy or dd-mm-yyyy or ddmmyy		//				or a period like mmyyyy or mm-yyyy or mm/yyyy		// Out: YYYYMMDD
		/*			Try to figure out what it is that the user entered:						ddmmyy(yy)			dd.mm.yy(yy)			(ww|mm)yy(yy)	- rare			(ww|mm).yy(yy)	- rare
			So we have to make some decisions.		*/
		// Replace all non-numeric characters by a dash		#zzdate1 = string(string_replaceregexp(#date1, -find='\\D', -replace='-'));
		if(string_findposition(#zzdate1, -find='-') != '-1');			#tmp = #zzdate1->split('-');			if(#tmp->size == 2);	// x-y				#tmp->get(1) = mv_fmtnum(#tmp->get(1),'##','R');				if(integer(#tmp->get(2)) == 0); 					#tmp->get(2) = '';				/if;				if(#tmp->get(2)->size < 4);	// yy					#tmp->get(2) = (integer(string(date->year)->substring(1,(4-#tmp->get(2)->size))) * 100) + integer(#tmp->get(2));				/if;			else;	// x-x-y				#tmp->get(1) = mv_fmtnum(#tmp->get(1),'##','R');				#tmp->get(2) = mv_fmtnum(#tmp->get(2),'##','R');				if(integer(#tmp->get(3)) == 0);					#tmp->get(3) = '';				/if;				if(#tmp->get(3)->size < 4);	// yy					#tmp->get(3) = (integer(string(date->year)->substring(1,(4-#tmp->get(3)->size))) * 100) + integer(#tmp->get(3));				/if;			/if;			#zzdate1 = #tmp->join('-');		else;			select(#zzdate1->size);			case(1);	// assume day				if(#action == 'FSD');					#zzdate1 = mv_fmtnum(#zzdate1,'##','R') + '-' + mv_fmtnum(date->month,'##','R') + '-' + string(date->year);				else;					#zzdate1 = '0';				/if;			case(2);	// assume day				if(#action == 'FSD');					#zzdate1 = mv_fmtnum(#zzdate1,'##','R') + '-' + mv_fmtnum(date->month,'##','R') + '-' + string(date->year);				else;					#zzdate1 = '0';				/if;			case(3);	// assume dmm/ddm or xyy (week or month)				if(#action == 'FSD');	// dmm/ddm					if(integer(#zzdate1->substring(2,2)) > 12);	// ddm						#zzdate1 = #zzdate1->substring(1,2) + '-' + mv_fmtnum(#zzdate1->substring(3,1),'##','R') + '-' + string(date->year);					else;	// dmm						#zzdate1 = mv_fmtnum(#zzdate1->substring(1,1),'##','R') + '-' + #zzdate1->substring(2,2) + '-' + string(date->year);					/if;				else;	// xyy					#zzdate1 = mv_fmtnum(#zzdate1->substring(1,1),'##','R') + '-' + string((integer(string(date->year)->substring(1,2)) * 100) + integer(#zzdate1->substring(2,2)));				/if;			case(4);	// ddmm or assume xxyy (week or month)				if(#action == 'FSD');	// ddmm or dmyy					if(integer(#zzdate1->substring(1,2)) > 31); // dmyy						#zzdate1 = mv_fmtnum(#zzdate1->substring(1,1),'##','R') + '-' + mv_fmtnum(#zzdate1->substring(2,1),'##','R') + '-' + string(date->year);					else;	// ddmm						#zzdate1 = #zzdate1->substring(1,2) + '-' + #zzdate1->substring(3,2) + '-' + string(date->year);					/if;				else;	// xyy					#zzdate1 = mv_fmtnum(#zzdate1->substring(1,2),'##','R') + '-' + string((integer(string(date->year)->substring(1,2)) * 100) + integer(#zzdate1->substring(3,2)));				/if;			case(5);	// assume ddmyy or dmmyy or xyyyy (if middle yy > 12)				if(integer(#zzdate1->substring(2,2)) > 12 && #action != 'FSD');	// xyyyy					#zzdate1 = mv_fmtnum(#zzdate1->substring(1,1),'##','R') + '-' + #zzdate1->substring(2,4);				else(integer(#zzdate1->substring(2,2)) <= 12);	// dmmyy					#zzdate1 = mv_fmtnum(#zzdate1->substring(1,1),'##','R') + '-' + #zzdate1->substring(2,2) + '-' + string((integer(string(date->year)->substring(1,2)) * 100) + integer(#zzdate1->substring(4,2)));				else;	// ddmyy					#zzdate1 = #zzdate1->substring(1,2) + '-' + mv_fmtnum(#zzdate1->substring(3,1),'##','R') + '-' + string((integer(string(date->year)->substring(1,2)) * 100) + integer(#zzdate1->substring(4,2)));				/if;			case(6);	// assume ddmmyy or xxyyyy (if middle yy > 12)				if(integer(#zzdate1->substring(3,2)) > 12 && #action != 'FSD');	// xxyyyy					#zzdate1 = #zzdate1->substring(1,2) + '-' + #zzdate1->substring(3,4);				else;	// ddmmyy					#zzdate1 = #zzdate1->substring(1,2) + '-' + #zzdate1->substring(3,2) + '-' + string((integer(string(date->year)->substring(1,2)) * 100) + integer(#zzdate1->substring(5,2)));				/if;			case(7);	// assume dmmyyyy or ddmyyyy				if(integer(#zzdate1->substring(2,2)) <= 12);	// dmmyyyy					#zzdate1 = mv_fmtnum(#zzdate1->substring(1,1),'##','R') + '-' + #zzdate1->substring(2,2) + '-' + #zzdate1->substring(4,4);				else;	// ddmyyyy					#zzdate1 = #zzdate1->substring(1,2) + '-' + mv_fmtnum(#zzdate1->substring(3,1),'##','R') + '-' + #zzdate1->substring(4,4);				/if;			case(8);	// assume ddmmyyyy				#zzdate1 = #zzdate1->substring(1,2) + '-' + #zzdate1->substring(3,2) + '-' + #zzdate1->substring(5,4);			/select;		/if;
		// Get only the numbers		#result = string(string_findregexp(#zzdate1, -find='\\d')->join(''));
		if(integer(#result) <= 0);			#result = '0';		else;			#tmp = #zzdate1->split('-');						// Check value of year			#year = integer(#tmp->get(#tmp->size));	// Last element			if(#year < 1 || #year > 9999);				#year = 0;				if(#action == 'FSD');					#year = date->year;				/if;			/if;
			if(#year >= 1 && #year <= 9999);				// Set last day of February				if(((math_mod(#year,4) == 0) && (math_mod(#year,100) != 0)) || (math_mod(#year,400) == 0));					#myMDAYS->get(2) = '29';				/if;
				// Check value of month or week				if(#tmp->size == 2);					#month = integer(#tmp->get(1));					if(#month < 1 || #month > 53);	// Week (we do not know if it is a month (max 12))						#month = 0;					/if;				else;					#month = integer(#tmp->get(2));					if(#month < 1 || #month > 12);						if(#action == 'FSD' && #month <= 0);							#month = date->month;						else;							#month = 0;						/if;					/if;				/if;								if(#month >= 1 && #month <= 12);					if(#tmp->size == 3);						// Check value of day						#day = integer(#tmp->get(1));						if(#day < 1 || #day > integer(#myMDAYS->get(#month)));							if(#action == 'FSD' && #day <= 0);								#day = date->day;							else;								#day = 0;							/if;						/if;												if(#day >= 1 && #day <= integer(#myMDAYS->get(#month)));							// add valid separators							#result = mv_fmtnum(#year,'####','R') + mv_fmtnum(#month,'##','R') + mv_fmtnum(#day,'##','R');						else;							#result = '0';						/if;					else;						#result = mv_fmtnum(#year,'####','R') + mv_fmtnum(#month,'##','R');					/if;				else;					#result = '0';				/if;			else;				#result = '0';			/if;		/if;			else((#action == 'TS') || (#action == 'NA')); // !TS, NA		// TS = To Screen		// In:  DATE1 = a Date from a database field, like YYYYMMDD or YYYY-MM-DD or YYYY.MM.DD or YYYY/MM/DD		//				or a period like yyyymm or yyyymm or yyyy/mm		// Out: DD-MM-YYYY
		// NA = Numeric to Alfa		// In:  DATE1 = a Date from a database field, like YYYYMMDD or YYYY-MM-DD or YYYY.MM.DD or YYYY/MM/DD		//				or a period like yyyymm or yyyymm or yyyy/mm		// Out: YYYY-MM-DD or blanks when date1 is zero.						// Replace all non-numeric characters by a dash		#zzdate1 = string(string_replaceregexp(#date1, -find='\\D', -replace='-'));
		// add valid separators		if(string_findposition(#zzdate1, -find='-') != '-1');			#myDate = #zzdate1->split('-');			if(#action == 'NA');				if(#myDate->size < 3);	// YYYY-MM					#result = date_format(#zzdate1, -format='%Y-%m');				else;					#result = date_format(#zzdate1, -format='%Y-%m-%d');				/if;			else;				if(#myDate->size < 3);	// YYYY-MM					#result = date_format(#zzdate1, -format='%m-%Y');				else;					#result = date_format(#zzdate1, -format='%d-%m-%Y');				/if;			/if;		else(integer(#zzdate1) == 0);			#result = '';		else;			select(#zzdate1->size);			case(1);				if(#action == 'NA');					#result = date->format('%Y') + '-' + '0' + #zzdate1;		// yyyy-mm				else;					#result = '0' + #zzdate1 + '-' + date->format('%Y');		// mm-yyyy				/if;			case(2);				if(#action == 'NA');					#result = date->format('%Y') + '-' + #zzdate1;		// yyyy-mm				else;					#result = #zzdate1 + '-' + date->format('%Y');		// mm-yyyy				/if;			case(3);				if(#action == 'NA');					#result = date->format('%Y') + '-0' + #zzdate1->substring(1,1) + '-' + #zzdate1->substring(2,2);		// mmd -> yyyy-mm-dd				else;					#result = #zzdate1->substring(2,2) + '-0' + #zzdate1->substring(1,1) + '-' + date->format('%Y');		// mmd -> dd-mm-yyyy				/if;			case(4);				if(#action == 'NA');					#result = date->format('%Y') + '-' + #zzdate1->substring(1,2) + '-' + #zzdate1->substring(2,2);		// mmd -> yyyy-mm-dd				else;					#result = #zzdate1->substring(3,2) + '-' + #zzdate1->substring(1,2) + '-' + date->format('%Y');		// mmdd -> dd-mm-yyyy				/if;			case(5);				if(#action == 'NA');					#result =  #zzdate1->substring(1,4) + '-' + '0' + #zzdate1->substring(5,1);		// yyyym -> yyyy-mm				else;					#result = '0' + #zzdate1->substring(5,1) + '-' + #zzdate1->substring(1,4);		// yyyym -> mm-yyyy				/if;			case(6);				if(#action == 'NA');					#result = #zzdate1->substring(1,4) + '-' + #zzdate1->substring(5,2);				// yyyymm / yyyyww -> yyyy-xx				else;					#result = #zzdate1->substring(5,2) + '-' + #zzdate1->substring(1,4);				// yyyymm / yyyyww -> xx-yyyy				/if;			case(7);				if(#action == 'NA');					#result = #zzdate1->substring(1,4) + '-' + #zzdate1->substring(5,3);		// yyyyddd -> yyyy-ddd				else;					#result = #zzdate1->substring(5,3) + '-' + #zzdate1->substring(1,4);		// yyyyddd -> ddd-yyyy				/if;			case;				if(#action == 'NA');					#result = #zzdate1->substring(1,4) + '-' + #zzdate1->substring(5,2) + '-' + #zzdate1->substring(7,2); // yyyymmdd -> yyyy-mm-dd				else;					#result = #zzdate1->substring(7,2) + '-' + #zzdate1->substring(5,2) + '-' + #zzdate1->substring(1,4); // yyyymmdd -> dd-mm-yyyy				/if;			/select;		/if;			else(#action == 'WM' || #action == 'WMD'); // !WM, WMD		// WM = Day in year of Monday of week, WMD = Date of this monday		// In:  DATE1 = a Week [[YY]YY{-|.|/}]WW				#zzdate1 = string(string_findregexp(#date1, -find='\\d')->join(''));
		if(#zzdate1->size >= 6);			// assume ???YYYYWW			#zzdate1 = #zzdate1->substring(1,6);		else(#zzdate1->size == 5);			// assume ?YYWW			#zzdate1 = '20' + #zzdate1->substring(2,4);		else(#zzdate1->size == 4);			// assume YYWW			#zzdate1 = '20' + #zzdate1;		else(#zzdate1->size == 3);			// assume YWW			#zzdate1 = '200' + #zzdate1->substring(1,1) + #zzdate1->substring(2,2);		else(#zzdate1->size == 2);			// assume WW			#zzdate1 = date->format('%Y') + #zzdate1;		else(#zzdate1->size == 1);			// assume W			#zzdate1 = date->format('%Y') + '0' + #zzdate1;		/if;
		#year = integer(#zzdate1->substring(1,4));		#week = integer(#zzdate1->substring(5,2));
		// Set last day of February		if(((math_mod(#year, 4) == 0) && (math_mod(#year, 100) != 0)) || (math_mod(#year, 400) == 0));			#myMDAYS->get(2) = '29';		/if;
		if(#week >= 1 && #week <= 53);			#wrk1 = #year - 1900 + integer((#year - 1900 - 1) / 4);			#wrk1 -= integer(#wrk1 / 7) * 7;			if(#wrk1 > 3);				#wrk1 -= 7;			/if;			#wrk2 = (#week * 7) - #wrk1 - 6;
			if(#wrk1 < 0 && #week == 53);				#year -= 1;				if(((math_mod(#year, 4) == 0) && (math_mod(#year, 100) != 0)) || (math_mod(#year, 400) == 0));					#myMDAYS->get(2) = '29';				/if;				#wrk2 -= 371;				#wrk2 += (#myMDAYS->get(2) == '29' ? 366 | 365);			else(#wrk2 <= 0);				#year -= 1;				if(((math_mod(#year, 4) == 0) && (math_mod(#year, 100) != 0)) || (math_mod(#year, 400) == 0));					#myMDAYS->get(2) = '29';				/if;				#wrk2 += (#myMDAYS->get(2) == '29' ? 366 | 365);			/if;
			if(#action == 'WMD');				#month = 0;				while(#wrk2 > 0);					#month += 1;					#wrk2 -= integer(#myMDAYS->get(#month));				/while;				#wrk2 += integer(#myMDAYS->get(#month));				#result = string((#year * 10000) + (#month * 100) + #wrk2);		// YYYYMMDD			else;				#result = (#year * 1000) + #wrk2;		// YYYYDDD			/if;		else;			#result = '';		/if;
	else(#action == 'DF' || #action=='SP'); // !DF, SP		// DF = Difference		// In:  DATE1 = a Date YYYY{-|.|/}MM{-|.|/}DD with or without a time HH{-|.|:}MM{-|.|:}SS, optionally separated by a space:		//		"YYYY-MM-DD HH:MM:SS", "YYYY.MM.DD HH.MM.SS", "YYYYMMDD HH:MM:SS", etc.		// In:  DATE2 = a Date YYYY{-|.|/}MM{-|.|/}DD with or without a time HH{-|.|:}MM{-|.|:}SS, optionally separated by a space:		//		"YYYY-MM-DD HH:MM:SS", "YYYY.MM.DD HH.MM.SS", "YYYYMMDD HH:MM:SS", etc.		// Out: array(days, hours, minutes, seconds), HMS are padded leading with zeros.
		// SP = Split into parts		// In:  DATE1 = a Date YYYY{-|.|/}MM{-|.|/}DD with or without a time HH{-|.|:}MM{-|.|:}SS, optionally separated by a space:		//		"YYYY-MM-DD HH:MM:SS", "YYYY.MM.DD HH.MM.SS", "YYYYMMDD HH:MM:SS", etc.		// Out: array(year, month, day, hour, minute, second), MDHMS are padded leading with zeros.
		#zzdate1 = (string_findregexp(#date1, -find='\\d')->join('') + '000000')->substring(1, 14);		#zzdate1->padleading(14, '0');
		if(#action == 'DF');			if(	integer(#zzdate1->substring(1,4)) > 0 &&				integer(#zzdate1->substring(5,2)) > 0 &&				integer(#zzdate1->substring(7,2)) > 0);								#zzdate2 = (string_findregexp(#date2, -find='\\d')->join('') + '000000')->substring(1, 14);				#zzdate2->padleading(14, '0');								if(	integer(#zzdate2->substring(1,4)) > 0 &&					integer(#zzdate2->substring(5,2)) > 0 &&					integer(#zzdate2->substring(7,2)) > 0);										if(#zzdate1 <= #zzdate2);						#neg = 0;						#tmp = date(#zzdate1)->difference(date(#zzdate2));					else;						#neg = 1;						#tmp = date(#zzdate2)->difference(date(#zzdate1));					/if;										#num = (duration(#tmp)->hour) / 24;					#tmp = #tmp - duration(-day=#num);					#result = string(string(#num) + ':' + string(#tmp))->split(':');										if(#neg == 1);						#result->get(1) = '-' + integer(math_abs(integer(#result->get(1))));						#result->get(2) = '-' + integer(math_abs(integer(#result->get(2))));						#result->get(3) = '-' + integer(math_abs(integer(#result->get(3))));						#result->get(4) = '-' + integer(math_abs(integer(#result->get(4))));					/if;				else;					#result = array('0','0','0','0');				/if;			else;				#result = array('0','0','0','0');			/if;					else(#action == 'SP');			#result = array('0','0','0','0','0','0');			#result->get(1) = #zzdate1->substring(1,4);			#result->get(2) = #zzdate1->substring(5,2);			#result->get(3) = #zzdate1->substring(7,2);			#result->get(4) = #zzdate1->substring(9,2);			#result->get(5) = #zzdate1->substring(11,2);			#result->get(6) = #zzdate1->substring(13,2);						#result->get(5)->padleading(2, '0');			#result->get(6)->padleading(2, '0');
		/if;					#result->get(2)->padleading(2, '0');		#result->get(3)->padleading(2, '0');		#result->get(4)->padleading(2, '0');	/if;		return(#result);/define_Tag;?>

Comments

09 Feb 2011, Marc Vos

Changes

Bug fixes & added (day in year or date) of monday of a week (WM & WMD).

Please log in to comment

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2014 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft