Baanboard.com

Go Back   Baanboard.com > Forum > Baan Quick Support: Functional & Technical > Tools Development

User login

Frontpage Sponsor

Main

Poll
What do you expect from your SI Implementation partner for the success of ERP implementation.
Bring best practices - Not to offer more CR's Leveraging standard functions
14%
Need more honesty to work with the Users until their processes are fully mapped & Users are trained
43%
Focus on process automation/ integrations/ Real time data/ BI analytics
29%
Stick to basics
14%
Total votes: 7

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 10th March 2023, 23:13
eric.dizon's Avatar
eric.dizon eric.dizon is offline
Senior Member
 
Join Date: Feb 2012
Posts: 158
eric.dizon is on a distinguished road
Baan: ERP LN - DB: MS SQL - OS: 2003
Calculating Current Day from Beginning of the year
Baan: Infor ERP 10.7
C/S: None/Unknown

https://www.epochconverter.com/daynumbers

Anybody has a function like this in Baan to return the value of the number of days from the beginning of the year e.g.

2023/01/10 = 10
2023/03/10 = 69
Reply With Quote
  #2  
Old 11th March 2023, 09:13
bdittmar's Avatar
bdittmar bdittmar is offline
Guru
 
Join Date: Apr 2002
Posts: 1,968
bdittmar will become famous soon enough
Baan: 2.2/3.1/4c4/LN6.1 FP6/FP9/HiDox Tools 10.7/D.3 - DB: tbase, ms-sql7, oracle10gV1, 11g, 12c, 19c - OS: HP-UX, W2K3, SLES, RHLE
sprintf$()

Hello,
use
Code:
Syntax:
function string sprintf$  (string format [, void ...])

Description

This formats a string and returns the formatted string. The format argument contains zero or more ordinary characters and substitution symbols. 
The ordinary characters are copied directly to the output string. 
The substitution symbols specify formats for the values specified in the expression arguments and are substituted by these formatted values. 

The substitution symbols are used in the sequence in which they are specified. The first substitution symbol is used for the first expression argument. 
The second substitution symbol is used for the second expression argument, and so on. 

In addition to a range of numeric type expressions, the function supports dates, amounts, single-byte strings, multibyte strings, bidirectional strings, 
and combined normal and bidirectional strings. input strings that contain bidirectional strings must be specified in logic order. 
The result is also returned in logic order. 

Arguments
string format contains zero or more ordinary characters and substitution symbols
 
[void ...]  One or more expressions to be replaced in the format

Implicit conversion of the input value is performed from its original type 
to the type expected according to the corresponding substitution symbol. 
 
Return values
The formatted string. If you specify an invalid format, sprintf$() returns a percentage character [%]. 

Context
This function is implemented in the porting set and can be used in all script types. 

%D xxx [ ,lang]  Use for dates.

xxx is the code for a date format defined in the data dictionary. lang indicates the language code to use. 
If this is omitted, the current user language is used. 

The expression that is substituted for this symbol must specify a number of days since 01-01-0001. 

Any date before 01-01-0001 (i.e. any integer value ≤ 0) will be interpreted as invalid and will print as an empty string

Any date past 31-12-9999 will be interpreted as 31-12-9999.

Note that it isn't possible to use a comma direct after a %D xxx substitution symbol other than for selecting a language. 
As a workaround select a space as the language code, this will substitute the users default language and close 
the type element. Now it is possible to use the comma that should be included in your string. 
See the example in the example section. 
 
%D( format)  Use for dates.

This option enables you to define your own date format by using the following subformats of the ‘%D’ format:

%m month in year 1 - 12 
%w week in year week 0 in previous year week 53 in current year 
%W week in year week 53 in previous year 
%d day in month 1 - 31 
%e day in week 1 - 7 
%j day in year 1 - 365 
%y year without century 01 - 99 
%Y year with century 1 - 9999 
%h name of month (‘Jan’ - ‘Dec’)

(abbreviated)
 
%H name of month (‘January’ - ‘December’) 
%a name of day (‘Sun’ - ‘Sat’)

(abbreviated)
 
%A name of day (‘Sunday’ - ‘Saturday’) 
 
You can combine these subformats with other formats. 
Note that strings returned by name of month and day formats are language dependent. 

The expression that is substituted for this symbol must specify a number of days since 01-01-0001. 

Any date before 01-01-0001 (i.e. any integer value ≤ 0) will be interpreted as invalid and will print as an empty string

Any date past 31-12-9999 will be interpreted as 31-12-9999.
 
%u xxx [ ,lang]  Use for UTC dates. xxx is the code for a UTC date format defined in the data dictionary. lang 
indicates the language code to use. If this is omitted, the current user language is used. 
The expression that is substituted for this symbol must specify a UTC long format value 
of which only the local date will be used. 

Any time before January 1, 1970, 00:00:00 UTC (i.e. any integer value < 0) will be interpreted as invalid and will print as an empty string 

Valid integer value 0 (corresponding to January 1, 1970, 00:00:00 UTC) will print as an empty string. 

Any local date past 31-12-9999 will be interpreted as 31-12-9999.

Note that it isn't possible to use a comma direct after a %u xxx substitution symbol other than for selecting a language. 
As a workaround select a space as the language code, this will substitute the users default language and close the type element. 
Now it is possible to use the comma that should be included in your string. See the example in the example section. 
 
%U xxx [ ,lang]  Use for UTC times. xxx is the code for a UTC time format defined in the data dictionary. lang indicates the language code to use. 
If this is omitted, the current user language is used. 
The expression that is substituted for this symbol must specify a UTC long format value of which only the local time will be used. 

Any time before January 1, 1970, 00:00:00 UTC (i.e. any integer value < 0) will be interpreted as invalid and will print as an empty string 

Valid integer value 0 (corresponding to January 1, 1970, 00:00:00 UTC) will print as an empty string. 

Note that it isn't possible to use a comma direct after a %U xxx substitution symbol other than for selecting a language. 
As a workaround select a space as the language code, this will substitute the users default language and close the type element. 
Now it is possible to use the comma that should be included in your string. See the example in the example section. 
 
%u( format)  Use for UTC dates.

This option enables you to define your own date format by using the subformats described for the ‘ %D( format)’ symbol. 
You can combine these subformats with other formats. 

Note that strings returned by name of month and day formats are language dependent. 

The expression that is substituted for this symbol must specify a UTC long format value of which only the local date will be used. 

Any time before January 1, 1970, 00:00:00 UTC (i.e. any integer value < 0) will be interpreted as invalid and will print as an empty string 

Valid integer value 0 (corresponding to January 1, 1970, 00:00:00 UTC) will print as an empty string. 

Any local date past 31-12-9999 will be interpreted as 31-12-9999.
 
%U( format)  Use for UTC times.

This option enables you to define your own time using the following subformats of the ‘%U’ format.

%H hours in 24 hour format 
%h hours in 12 hour format 
%m minutes 
%s seconds 
%a substitutes the am/pm symbol as defined for the user language  
%x time separator as specified for the user language 
 
You can combine these subformats with other formats. 

The expression that is substituted for this symbol must specify a UTC long format value of which only the local time will be used. 

Any time before January 1, 1970, 00:00:00 UTC (i.e. any integer value < 0) will be interpreted as invalid and will print as an empty string 

Valid integer value 0 (corresponding to January 1, 1970, 00:00:00 UTC) will print as an empty string.
Code:
Example:
Dates
| Suppose date format 002 is: "year/month/day in month"
string result(80)
>result = sprintf$("%D002", 727168)
    | result contains "1991/12/2"
	| Example of substitution symbol %D(format)
string result(80)
result = sprintf$("%D(Date: %02d/%02m/%04Y)", date.num())
    | result contains "Date: 12/07/1993"
result = sprintf$("Date: %D(%02d %-20H %04Y)", date.num())
    | result contains "Date: 12 June 1993"
	UTC dates and times
| Date format 002 is "year/month/day in month"
| Time format 001 is "12 hour format:minutes:seconds AM/PM symbol"
string result(80)
result = sprintf$(" %001", utc.num(), utc.num())
    | Result contains "1997/01/01 10:02:53 pm"
	string result(80)
result = sprintf$("UTC: %u(%02d/%02m/%04Y) %U(%02h%x%02m%x%02s %a)", utc.num(), utc.num())
    | result contains "UTC: 22/07/1997 06:24:53 am"
    | provided that for the user's language the time
    | separator is ":" and the AM symbol is "am"
	| Using a comma after a %u substitution symbol		
string result(80)		
result = sprintf$(", ,Message text....", utc.num())			
    | result containts "06-05-15,Message text...."
Regards
__________________
//Bernd

Last edited by bdittmar : 11th March 2023 at 14:50.
Reply With Quote
  #3  
Old 11th March 2023, 15:15
vahdani's Avatar
vahdani vahdani is offline
Guru
 
Join Date: Aug 2002
Location: Cologne, Germany
Posts: 481
vahdani is on a distinguished road
Baan: all - DB: all - OS: Unix / Win2K
you can use the standard function date.to.num() to find the number of days since 01-01-0001 for the "start of the year" and "the other date" and then substract these to get the number of days since the beginning of the year!

Here my suggestion for a function to do this:

Code:
function long	days.in.year.for.date(	long	i.year,
					long	i.month,
					long	i.day)
{
	long	l.start.of.year.days
	long	l.this.date.days
	long	l.days.in.year.for.date
	
	l.start.of.year.total.days = date.to.num  (i.year, 1, 1)
	
	l.this.date.total.days = date.to.num  (i.year, i.month, i.day)

	l.days.in.year.for.date = l.this.date.days - l.start.of.year.days + 1
	
	return( l.days.in.year.for.date )

}
__________________
May the force be with you!

Last edited by vahdani : 15th March 2023 at 11:59. Reason: Correction
Reply With Quote
  #4  
Old 13th March 2023, 16:22
OmeLuuk's Avatar
OmeLuuk OmeLuuk is offline
Guru
 
Join Date: Mar 2002
Location: Belgium
Posts: 1,288
OmeLuuk will become famous soon enough
Baan: Infor LN 6.1 10.2.1 > 10.7 - DB: MS SQL2017 - OS: VM WindowsServer2016
Quote:
Originally Posted by bdittmar View Post
Hello,
use
Code:
Syntax:
function string sprintf$  (string format [, void ...])
...
%D( format)  Use for dates.
...
This option enables you to define your own date format by using the following subformats of the ‘%D’ format:
%j day in year 1 - 365 
...
Code:
Example:
result = sprintf$("%D(Date: %02d/%02m/%04Y)", date.num())
    | result contains "Date: 12/07/1993"
Regards
Would result in
Code:
result = "This year already counts " & sprintf$("%D(%j)",date.num()) & " days."
__________________


Also read Luke 24:4-8

After that you can find many answers on Infor, LN, BaanIV, BaanV, InforLN and ION and even some questions asked here on baanboard.com
Reply With Quote
Sponsored Links
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Kalenderwoche MS-Tech Deutsches Forum 3 23rd February 2017 19:24
Inventory Opening balance manual update for the current year murali.mani Blogs and Web links 1 17th June 2011 15:04
Need some guide regarding variable converting.. jpradips Tools Development 2 31st December 2007 09:38
Changing current Fiscal Year benito Finance, Invoicing and Integration 3 6th March 2002 19:43


All times are GMT +2. The time now is 03:15.


©2001-2023 - Baanboard.com - Baanforums.com