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

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
greg falda
Posts: 77
Joined: Thu Jan 15, 2015 6:51 pm
Location: Warsaw

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

Post by greg falda » Wed Nov 16, 2016 3:30 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Wed Nov 16, 2016 4:54 pm

I could not find your earlier post. What is this in reply to?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » Wed Nov 16, 2016 5:04 pm

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

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Wed Nov 16, 2016 5:06 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Wed Nov 16, 2016 5:29 pm

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."
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » Wed Nov 16, 2016 5:54 pm

Richard,

Link works for me. It likes me better?

Craig

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Wed Nov 16, 2016 6:53 pm

dunbarx wrote:Link works for me. It likes me better?
What is the title of that forum?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Klaus
Posts: 13829
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

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

Post by Klaus » Wed Nov 16, 2016 7:28 pm

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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Wed Nov 16, 2016 7:33 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

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

Post by FourthWorld » Wed Nov 16, 2016 7:41 pm

@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?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

greg falda
Posts: 77
Joined: Thu Jan 15, 2015 6:51 pm
Location: Warsaw

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

Post by greg falda » Mon Nov 21, 2016 5:00 pm

@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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

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

Post by dunbarx » Mon Nov 21, 2016 5:25 pm

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

ghettocottage
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 366
Joined: Tue Apr 10, 2012 9:18 am

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

Post by ghettocottage » Mon Nov 21, 2016 5:33 pm

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

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

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

Post by AxWald » Tue Nov 22, 2016 1:27 pm

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!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

greg falda
Posts: 77
Joined: Thu Jan 15, 2015 6:51 pm
Location: Warsaw

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

Post by greg falda » Tue Dec 06, 2016 1:03 pm

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

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”