A Macro for Base to strip out the year

Creating a macro - Writing a Script - Using the API

A Macro for Base to strip out the year

Postby LJ Bettona » Wed Aug 20, 2008 11:56 am

I am trying to create a questionnaire database that will be used once each year for who knows how many years. I want to record simply the year the questionnaire was filled in.

I was pointed to the FUNCTIONS list and tried all the variations you can imagine around YEAR(), CURDATE(), CURRENT_TIMESTAMP, TO_CHAR() and I can't remember which others. I entered these into the SQL window in this command:


No matter what's at the end of the command I get this error:

Wrong data type or data too long in DEFAULT clause: YEAR(CURDATE()) in statement [ALTER TABLE "Respondent"ALTER COLUMN "RespondentYear" SET DEFAULT "YEAR(CURDATE())"]

I have altered the field type for RespondentYear many times:
char fixed (100 also 4)
var char (100)
still the same error.

If I remove the " " around the function it just balks at YEAR.

OK. That's the history; why I'm here.

Is there a macro that will do this? I searched this forum for Year Base and got nil response hence this post. The macros list doesn't seem to include one either.

What I want to do is either a simple YEAR(CURDATE()), or store CURDATE() in some temporary variable and apply YEAR() to that variable. I tried something like that with what little I remember but it doesn't work. Could be the functions don't exist in the basic that is being used.

It has been decades since I wrote macros in basic so assume I have forgotten all I knew.

Thanks for any help.
iMac G5, OS 10.4.11
OO 2.4, NeoOffice 3 patch 1
OOo 2.2.X on Mac OSx other + Actually NeoOffice 3 patch 1
User avatar
LJ Bettona
Posts: 58
Joined: Fri Jan 04, 2008 12:31 pm
Location: Italy

Re: A Macro for Base to strip out the year

Postby DrewJensen » Sat Aug 23, 2008 8:57 pm

The function YEAR returns an INTEGER - so your data type would be INTEGER

The function TO_CHAR returns a string so your data type would be CHAR or VARCHAR

I hope that helps.
Former member of The Document Foundation
Former member of Apache OpenOffice PMC
LibreOffice on Ubuntu 18.04
User avatar
Posts: 1734
Joined: Sat Oct 06, 2007 9:01 pm
Location: Cumberland, MD - USA

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 4 guests