Page 1 of 1

Dealing with zero date (null value) to represent:no date set

Posted: Wed Nov 16, 2016 3:30 pm
by greg falda
Hello!

Please look at my question. Sadly, no one answered me before :-(
I try now to clarify my question - in short: How to set and check a null-value for date? (which I internally use for "no date value set here")

What I call zero date is Jan 1 st 1970 (this is in fact the earliest date to be set in Livecode)

I would like to have the following code:

Set tDate to zero date and then check this fact, i.e. someting like:

Code: Select all

local tDate
put (...) into tDate ## 1.
if (tDate = ...)        ## 2.
    answer "tDate is zero-date"
else
   answer "tDate is not zero-date"
end if
The code should work as follows:
Line ## 1. tDate should get the value of Jan 1 st 1970. What should I write in place of the (...)
Line ## 2. The above fact should be positively checked, hence the if should return YES, i.e. I should see a popup with "tDate is zero-date". What should I write in place of the ... ?

Please provide a working code, i.e. fill the ... in lines ## 1. and ## 2. . Any help will be appreciated.
Best,
Greg Falda

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 4:54 pm
by FourthWorld
I could not find your earlier post. What is this in reply to?

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 5:04 pm
by dunbarx
What I call zero date is Jan 1 st 1970 (this is in fact the earliest date to be set in Livecode)
You can get dates earlier than that. Please see the thread "When was the Big Bang"

Craig

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 5:06 pm
by Klaus
FourthWorld wrote:I could not find your earlier post. What is this in reply to?
http://forums.livecode.com/viewtopic.php?f=94&t=27847

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 5:29 pm
by FourthWorld
Klaus wrote:
FourthWorld wrote:I could not find your earlier post. What is this in reply to?
http://forums.livecode.com/viewtopic.php?f=94&t=27847
Thanks. When I click that link I get:
"You are not authorised to read this forum."

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 5:54 pm
by dunbarx
Richard,

Link works for me. It likes me better?

Craig

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 6:53 pm
by FourthWorld
dunbarx wrote:Link works for me. It likes me better?
What is the title of that forum?

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 7:28 pm
by Klaus
FourthWorld wrote:What is the title of that forum?
Board index ‹ Private ‹ Create it With LiveCode

As a moderator you should be permitted to view that forum, right?

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 7:33 pm
by FourthWorld
Klaus wrote:
FourthWorld wrote:What is the title of that forum?
Board index ‹ Private ‹ Create it With LiveCode

As a moderator you should be permitted to view that forum, right?
I am now. I was unable to change my permissions previously because forums are only shown in the PHPBB UI by name, and I had only the ID. Thanks to your help in providing the name, I was able to add myself there.

I've also taken the liberty of removing the confusing nested quote blocks from the OP here so we can more readily focus on the actual issue described there.

Re: Dealing with zero date (null value) to represent:no date

Posted: Wed Nov 16, 2016 7:41 pm
by FourthWorld
@Greg: It may be helpful to understand more about the context of your code. To start with, is tDate coming from a user-entered value? If so, where does the user enter that value? If not, where does it come from?

Re: Dealing with zero date (null value) to represent:no date

Posted: Mon Nov 21, 2016 5:00 pm
by greg falda
@FourthWorld and all :
FourthWorld wrote:@Greg: It may be helpful to understand more about the context of your code. To start with, is tDate coming from a user-entered value? If so, where does the user enter that value? If not, where does it come from?
OK.

Thank you for your question.

The overall goal is simple : I want to keep in the SQL database of my application a "date" Value. For instance : "deadline date" of a task. If the task has no deadline date (it is a possible case, for instance if it is abonus task), I would like to keep the information : "no deadline date set" in (potentally) any possible way.

I've already implemented a UI which enables the user to enter a date, or - instead of it - the info "no date set" (by clicking a dedicated button). I only miss a way to represent "no date set" in a date value.

It could be done for sure with 2 fields :

Code: Select all

1) Deadline date (a date)
2) Is there any deadline date set?  (a boolean)
In my current app, however, I've chosen a different way : I've planned to keep all the info in one value (just : a date) and hence to keep somehow the info "no date set" in the date itself. What makes most sesne to me is to keep the "no date set" in the date which has numeric value 0 - I will not need it as a real date, since it is in the past.

In my current code, all I need to make it working is to fill the ... in this sample code, I repeat it here:

Code: Select all

local tDate
put (...) into tDate ## 1. It should put the date value meaning "no date set"
if (tDate = ...)        ## 2. Here, I would like to check if the date stores real date or just the info : "no date set"
    answer "tDate is zero-date"
else
   answer "tDate is not zero-date it is" && tDate
end if
Thanks a lot in advance for any further help :lol:
Best,
greg falda

Re: Dealing with zero date (null value) to represent:no date

Posted: Mon Nov 21, 2016 5:25 pm
by dunbarx
Hi.

You know it is possible to simply ask if a value "is a" date, and by that I mean to use the "is a" operator.

That said, note that date formats are varied, and you must be careful, because:

Code: Select all

answer "123" is a date
answer 12.3" is a date
answer pi is a date
will all return "true". This requires careful planning. The other way to possibly check is to parse your favorite date format and make sure each potion is valid.

Craig Newman

Re: Dealing with zero date (null value) to represent:no date

Posted: Mon Nov 21, 2016 5:33 pm
by ghettocottage
My thoughts: Because you will not be storing the string "no date set" in your SQL date field, but rather it will be empty if no date is set.

working backwards from that:

if you are requesting data from your database, you would put that value from the field into tDate, then use your if statement:

Code: Select all

if tDate is empty then
put "no date set" into tDate
 end if
put tDate into field "deadLine"  --or whatever that field is named 
if you are sending data to your database, you would first do something like:

Code: Select all

put field "deadLine" into tDate
if tDate is not a date then
  put empty into tDate
end if

Re: Dealing with zero date (null value) to represent:no date

Posted: Tue Nov 22, 2016 1:27 pm
by AxWald
Hi,

what he said. ^^^^

The easy way to have "no special date" is to have "no date at all". The SQL would see this as "NULL", LC interprets it as empty.

Just in case you need to differentiate between "no date at all" and "no special date":

Code: Select all

UPDATE `MyTable` SET MyDate = '0000-00-00' WHERE  ID = 1;
Be careful, LC might interpret both as empty - but SQL differentiates between "NULL" and "0000-00-00" (SELECT queries in MySQL at least, tested).

Have fun!

Re: Dealing with zero date (null value) to represent:no date

Posted: Tue Dec 06, 2016 1:03 pm
by greg falda
Dear all

Thank you for your valuable help. I finally managed it by keeping (in the same db field) the date (if date has been set by user) or the string "no date set" (if user decided that no date should be set in this place). Now it works.

Best,
greg falda