last day (15 days later) » 

3:17 PM
0
A: Trouble with date ranges

John RuddellTry using INTERVAL and either NOW() or CURDATE() WHERE CAL_CREATED BETWEEN CURDATE() - INTERVAL 30 DAY AND CURDATE() curdate is just the date portion of the day if you want to include the time use NOW() WHERE CAL_CREATED BETWEEN NOW() - INTERVAL 30 DAY AND NOW() you could also make a new d...

 
When I use any of the 3 I get this it does not error, but results in MySQL returned an empty result set (i.e. zero rows). (Query took 0.0077 sec)
 
@Detox did you try CURDATE()?
@Detox not sure how NOW() is throwing an error... i added a reference in my answer. try using a different date format.. see my edited answer
 
yes, and it results in no data found = MySQL returned an empty result set (i.e. zero rows). (Query took 0.0079 sec)
 
@Detox try using my full query it may have something to do with how you pull out cal_created as UNIX instead of just regular date_format
 
I tried all 3 again. No errors, but no data found. That is the confusing part. When I run the query without that line is shows all entries fine. However, I'd hate to parse out un-needed data each time. I appreciate your help
John are you saying to copy the full query as above? if so I did and no success
 
3:18 PM
hey
 
Now, the actual data is int, and I am converting to readable in the query what if I take that line out?
 
i forgot to change the WHERE in the query
 
oh and thanks so much for yoru time
 
so it was the incorrect part that you had posted
so try it again with the correct INTERVAL
sure thing :)
 
please say that again?
 
3:19 PM
what line are you referring to taking out?
ok
so when I posted the FULL QUERY: edit to my post
 
FROM_UNIXTIME(cal_created, "%m-%d-%y")AS Created,
should I pull that out?
 
I copied your query
but when I copied it
 
k
 
I changed the FROM_UNIXTIME
to DATE_FORMAT
 
ahhh
 
3:21 PM
but I forgot to change the WHERE
so the where was still incorrect
WHERE date BETWEEN( NOW() - '30day')
that part was incorrect
 
am very new to this part of stackoverflow how cn I chat here and still see the psotings?
postings?
I think I got it
give me a sec to copy paste
 
ok
you can hit the back button
so you can see the post
and then open the chat window in a new tab
 
well drat,, still no results query runs
 
ok
can you add some sample data?
i can play with it and get it working
 
sure I think how do I do that send a csv file?
 
3:26 PM
hmmm
well if you wanna share a google drive doc I can pull it down
 
yes I am not the brightest guy still reading books and learinnig as I go
 
no problem :) thats what SO is for
 
do not have one of thos
"SO"
?
 
Stack Overflow = SO
 
oh stack overflow?
 
3:27 PM
abbreviation
yea
 
k
 
hmm
email?
 
hmmm ok let me figure how to do this as this is patient data and the HIPAA / privacy cops run rampant
 
ok well wait
i don't want you to get in trouble
 
will take a few min to toss a few garbage entries and and export to csv or excel
na,, I can use sample cleints
 
3:28 PM
ok yea
good
 
will take me a min to create the entries
 
my email is my name
johnruddell@gmail.com
 
awesome! I am sklund@coastalhorizons.org Steve Klund
 
ok cool
 
will get it packaged in a few thank you so much! I can help some folks with very basic stuff but some things I just get befuddled over still well actually, a lot of stuff I get befuddled over
making entries now let me have 10 min
 
3:31 PM
i'm not a mysql genius either... but sometimes a simple format can cause this whole issue
no prob
i got all day lol
 
3:44 PM
ok on the way
exported as csv, opened on apache office to make sure all data is there sent as attachemnt
 
ok
so i got it
but I dono what im looking at lol
this is an image of it
 
yes,, when you open in excel ya gotta include headers
that will make it easier
 
I have a Mac so how would I do that in the mac version?
not sure how to include headers... (i know excel but not that well lol)
 
ohh ok thinking
do you have openoffice?
I can repackage I think for mac
give me a sec
 
well
if you can just take a screenshot
of the sample data
i can see what it looks like
and fix on my side
 
3:53 PM
ok sending in plain csv
sorry did ya get it?
and does that work better?
 
ok
i got it
but it was still the same
but
 
great
 
i think i fixed it
i used some functions
 
whoopie
 
to do this
is that correct??
 
4:00 PM
yup
 
ok
so now where is the date?
is it cal_created?
 
yes
 
there are several, but the cal_created is what I am pulling the report on
 
and does cal_created look exactly like that in the database?
 
4:02 PM
to see how many referrals staff do in a specific timeframe
yes
 
ok ill look at it and get back to you via email
 
screencast.com.t/v8glyT3Nmg
screencast.com/t/v8glyT3Nmg
this is screenshot of all the fields
second one top has typeo
BTW, I do not know how much info is allowed, I'm in North Carolina so if you are close I'll sport you a pot of coffee and a prune danish
 
4:34 PM
sorry i was in a meeting at work
 
no problem
 
im in texas lol its no problem
i like helping people out :)
 
ahh longhorn state
 
how is cal_created stored in the database?
what is its datatype?
 
did you see the screenshot I made for you?
screencast.com/t/v8glyT3Nmg
 
4:35 PM
ok yea
cool
one sec
 
int (11)
 
ok
solved it
 
wow
 
the problem is cal_created is the int(11) so when you do the check BETWEEN
it doesn't recognize it
basically
do this.....
 
story of my life with queries
 
4:41 PM
WHERE FROM_UNIXTIME(CAL_CREATED) BETWEEN (NOW() - INTERVAL 30 DAY) AND NOW()
convert it to a date and then do the between
I edited my query to do the same :)
 
ends in may jun jul missing
are you getting the 4 entries returned?
first entry returned is 03-00-14 last os 05-08-14
 
yea i am getting those 4
 
arrggg what am I missing
 
hmm
one sec
can you just send me the timestamp
the int
for like the start and end?
like the 03 and the 05
and i can add those to this and see if they get filtered out
 
oh i think so from the query?
 
4:47 PM
yea
 
ok one sec
 
like whatever row is being returned
the actual number
 
ok pruned out cal_owner and left everything else for full query
that way you can sort as you wish
cal_title I meant that way no client data
sent email
 
hmm
well thats not exactly what I was asking for
but try this
this should work
 
thought it would give you a better sampling of data
 
4:53 PM
WHERE cal_created BETWEEN UNIX_TIMESTAMP(NOW() - interval 30 day) AND UNIX_TIMESTAMP(NOW())
 
I can resend
 
no prob
it does to an extent but I was more reffering to the integer for the date
try that WHERE though
 
same result
 
hmm
ok can you send me the integers for the dates?
 
can you please explain what you want do not uderstand
 
4:54 PM
just the integers
 
ahh
ok
 
yea not the date formatted
just send me like 50 integers
that are over like 3 months
you may want to actually format the date first and then query off of it
i can show you how to do that once i update my sample table with your data :)
 
ok coming your way
that would be great
 
ok
so i just ran the query
 
just put snag-it on this pc making screenshots easier and quicker
do we shoot it at sunrise?
 
5:06 PM
I added 200 of the 5k rows u gave me
the dates go from april to july
from the 200 i added
 
yes
 
when I run the query
it works
 
yippeeeee
 
specifically this
where cal_created BETWEEN UNIX_TIMESTAMP(NOW() - interval 30 day) AND UNIX_TIMESTAMP(NOW());
which you were saying doesnt work
so im honestly not sure whats different between that and this
but you can also try this
 
ok let's paste the whole query from your end maybe I have scrambled it?
please
 
5:10 PM
well its not that simple
I made a sample database
with just the dates
so my query isn't going to look like yours
 
right
 
so
try running this
 
and that is all I'm pulling
 
SELECT * FROM(
SELECT CAL_OWNER,
CAL_TITLE,
FROM_UNIXTIME (CAL_CREATED, '%m-%d-%y') AS CREATED_AT,
FROM_UNIXTIME (RANGE_START, '%Y-%m-%d') AS DATE2BESEEN,
CASE CAL_REFERRAL_TYPE
WHEN 1 THEN 'NoReferral'
WHEN 2 THEN 'CareyGuide'
WHEN 3 THEN 'Education'
WHEN 4 THEN 'Employment'
WHEN 5 THEN 'Housing'
WHEN 6 THEN 'Medical'
ELSE 'NA'
END
AS REFERRALS
FROM EGW_CAL
ORDER BY REFERRALS ASC
)as temp
WHERE CREATED_AT BETWEEN (NOW() - INTERVAL 30 DAY) AND NOW();
this is what it looks like formatted... screencast.com/t/MnZP75PGoKn
basically do your select... then filter the results in a where outside of that select
that way the date is formatted
hopefully that will do what you want it to
this is my query that returns the correct dates on what you were asking to see
and this is what is in the sample database
so you can see my query works.. but it doesn't with yours for some reason
 
yes and i see it is splendid
 
5:18 PM
did you try running the big query I pasted?
 
now, when I run the query exactly as you posted it, I get no results, if I comment the 90 window all data runs perfectly I am at a loss the good news is it is closes
closer
 
90 window?
 
sorry 30 day
 
so if you remove the WHERE you are sayin?
 
comment this -- WHERE CREATED_AT BETWEEN (NOW() - INTERVAL 30 DAY) AND NOW(); and query pulls all data
yup
uncomment and shows zero results
i know,,, (Grrrrrrr)
 
5:20 PM
could you show me what it looks like when you return the query without the where?
 
sure
this is just the 1st page
but added in the query so you could see I pasted what you gave me
 
yea
ok
good... now can you just do this
 
? scream wildly into the nite?
 
SELECT NOW();
sorry my computer is getting old... sometimes it locks up for a sec lol
 
I think this is becoming a "no good deed goes unpunished"
 
5:28 PM
lol i know what the issue is
your formats are not compatible
 
instead of the where clause we have?
 
you need to do '%y-%m-%d'
no just by itself as its own select
you will see its in yyyy-mm-dd format
and you are comparing mm-dd-yyy
 
ok y m d in cal created right?
 
yea
as CREATED_AT
then the WHERE on CREATED_AT should work
 
this pulls the data, but, it loops a number of times
running same data
 
5:32 PM
yea it would loop twice
so now
you can make this one query
without the two selects
 
whew
dump cal_owner?
 
k
 
building the query one sec
 
ahh I see the select * and the selct inside th (
 
5:34 PM
yea
so i just emailed you
i emailed you the query and formatted it so its easier for you
that should work
I also updated my full query for you to see it there
full query in the answer I posted :)
 
Zounds!
I gotta figure out how to get you a hunk of coffee
 
haha
its cool buddy
Dates are srsly so annoying because they have to be in the exact correct format
 
looks like it works fine had to un capitalize some stuff
yes agree
 
ok sweet
very glad I could help you
:)
 
did not like
EGW_CAL
 
5:39 PM
good luck with your work!
 
but egw_cal is good
thank so much
 
of course
dont forget to accept the answer :)
 
and really if I can do anything for you let me know
 
i updated it to the correct response
 
will do
 
5:40 PM
lol its no problem.. if you have any more questions feel free to email me. you hav my email!
 
thank you so much!
 
pleasure is all mine :)
 

last day (15 days later) »