UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Return "today" If Current Date, Actual Date Otherwise, Office 2010    
 
   
bakersburg9
post Apr 11 2012, 07:17 PM
Post #1

UtterAccess Ruler
Posts: 4,238
From: Downey, CA



I have a report that documents what I've been working on - I have a ddd format, so today Wednesday, would be Wed 5:13 p.m. for example - I'm trying to add an alias field to my query to where if the date is today's date, return Today 5:13 p.m. otherwise if it was yesterday or the day before, I want say Tues 3:57 p.m for example.

If it was a week ago, I would want the month number and day ONLY, i.e, Tues 4/3, with no time of day

here is my sql
CODE
SELECT TOP 25 tblProjectWorkLog.ID, tblProjectWorkLog.ProjID, tblProjectWorkLog.Start, tblProjectWorkLog.End, tblProjectWorkLog.Completed, tblProjectWorkLog.Notes, tblProjectWorkLog.DateUpdated
FROM tblProjectWorkLog

and the alias attempt that did NOT work:
CODE
StrtDt: IIf([start]=Date(),"Today",[start])

Go to the top of the page
 
+
GroverParkGeorge
post Apr 11 2012, 07:31 PM
Post #2

UA Admin
Posts: 19,250
From: Newcastle, WA



If you are storing your [start] values with a time component, they CAN'T be the same as the value returned by Date(). In other words, 4/11/2012 5:30PM is NOT the same as 4/11/2012.

I think that's the problem here. You will need to get the DateValue from [start] and compare that to the current Date().
Go to the top of the page
 
+
John Vinson
post Apr 11 2012, 07:52 PM
Post #3

UtterAccess VIP
Posts: 2,550
From: Parma, Idaho, US



try:

=IIF(DateValue([start]) = Date(), TimeValue([start]), DateValue([start])
Go to the top of the page
 
+
raskew
post Apr 12 2012, 02:13 AM
Post #4

UtterAccess Guru
Posts: 805



Hi -

The Switch() function may do it for you. Here are three examples (today, yesterday, 8 days ago):

CODE
'****************************************************************************
x = now()
y = switch(datevalue(x) = date(), "Today " & cstr(format(timevalue(x), "hh:nn ampm")), x >= date()-7, format(x, "ddd hh:nn ampm"), True, format(x, "ddd m/d"))
? y
Today 02:06 AM
'****************************************************************************

x = now()-1
y = switch(datevalue(x) = date(), "Today " & cstr(format(timevalue(x), "hh:nn ampm")), x >= date()-7, format(x, "ddd hh:nn ampm"), True, format(x, "ddd m/d"))
? y
Wed 02:07 AM
'****************************************************************************

x = now()-8
y = switch(datevalue(x) = date(), "Today " & cstr(format(timevalue(x), "hh:nn ampm")), x >= date()-7, format(x, "ddd hh:nn ampm"), True, format(x, "ddd m/d"))
? y
Wed 4/4
'****************************************************************************


HTH - Bob

This post has been edited by raskew: Apr 12 2012, 02:15 AM
Go to the top of the page
 
+
Gustav
post Apr 12 2012, 05:29 AM
Post #5

UtterAccess VIP
Posts: 1,829



You could use:

StrtDt: Format([Start], IIf(DateValue([Start])=Date(), "\T\o\d\a\y", "dddd") & " h:nn AM/PM")

/gustav
Go to the top of the page
 
+
bakersburg9
post Apr 12 2012, 12:20 PM
Post #6

UtterAccess Ruler
Posts: 4,238
From: Downey, CA



QUOTE (raskew @ Apr 12 2012, 07:13 AM) *
The Switch() function may do it for you. Here are three examples (today, yesterday, 8 days ago):

Bob and everyone, thanks !!!

Bob - how would I call that function from a query ?
Go to the top of the page
 
+
raskew
post Apr 12 2012, 01:48 PM
Post #7

UtterAccess Guru
Posts: 805



Hi -

Here's a tested example. You'll need to replace the table and field names with your own. I limited it to records > 1 Feb 2012, you'll probably need to modify or eliminate this criteria.

CODE
SELECT tblTransfer.CatID, Switch(DateValue([expDte])=Date(),"Today " & CStr(Format(TimeValue([expDte]),"hh:nn ampm")),[expdte]>=Date()-7,Format([expdte],"ddd hh:nn ampm"),True,Format([expdte],"ddd m/d")) AS x, tblTransfer.ExpDte
FROM tblTransfer
WHERE (((tblTransfer.ExpDte)>#2/1/2012#))
ORDER BY tblTransfer.ExpDte DESC;


HTH - Bob
Go to the top of the page
 
+
bakersburg9
post Apr 12 2012, 01:56 PM
Post #8

UtterAccess Ruler
Posts: 4,238
From: Downey, CA



QUOTE (raskew @ Apr 12 2012, 06:48 PM) *
Hi -

Here's a tested example. You'll need to replace the table and field names with your own. I limited it to records > 1 Feb 2012, you'll probably need to modify or eliminate this criteria.

CODE
SELECT tblTransfer.CatID, Switch(DateValue([expDte])=Date(),"Today " & CStr(Format(TimeValue([expDte]),"hh:nn ampm")),[expdte]>=Date()-7,Format([expdte],"ddd hh:nn ampm"),True,Format([expdte],"ddd m/d")) AS x, tblTransfer.ExpDte
FROM tblTransfer
WHERE (((tblTransfer.ExpDte)>#2/1/2012#))
ORDER BY tblTransfer.ExpDte DESC;


HTH - Bob


bob - thx but I didn't get the CatID part (IMG:style_emoticons/default/frown.gif)

Steve
Go to the top of the page
 
+
Jeff B.
post Apr 12 2012, 01:56 PM
Post #9

UtterAccess VIP
Posts: 8,170
From: Pacific NorthWet



Uhm...? I may be missing something, but if you run a "report" and it has "Today" on it, how will you be able to tell which one of those you ran last week (that ALL say "Today" on them) "belongs" to last Thursday's data?
Go to the top of the page
 
+
bakersburg9
post Apr 12 2012, 01:58 PM
Post #10

UtterAccess Ruler
Posts: 4,238
From: Downey, CA



QUOTE (Jeff B. @ Apr 12 2012, 06:56 PM) *
Uhm...? I may be missing something, but if you run a "report" and it has "Today" on it, how will you be able to tell which one of those you ran last week (that ALL say "Today" on them) "belongs" to last Thursday's data?

Jeff,
thx 4 taking a look - it's a report to be ran daily and not archived so if it's a note/comment from today, I want it to say "TODAY"

CODE
St_Date: Format([Start],IIf(DateValue([Start])=Date(),"\T\o\d\a\y","ddd") & " h:nn AM/PM")


Steve
Go to the top of the page
 
+
raskew
post Apr 12 2012, 03:29 PM
Post #11

UtterAccess Guru
Posts: 805



QUOTE
bob - thx but I didn't get the CatID part

'**********************************************
This was just a field in my test table.
It's not significant to the Switch()function and can be eliminated without harm.

Bob
Go to the top of the page
 
+
raskew
post Apr 12 2012, 04:58 PM
Post #12

UtterAccess Guru
Posts: 805



Hi -

I'm confused. You've double-posted the same problem -- a forum no-no.

The example I provided returns exactly what you asked for.

If there's a problem creating the query against your table, please download a sample table (with data) and
we should be able to demonstrate the solution.

Best wishes - Bob
Go to the top of the page
 
+
bakersburg9
post Apr 13 2012, 11:10 AM
Post #13

UtterAccess Ruler
Posts: 4,238
From: Downey, CA



QUOTE (raskew @ Apr 12 2012, 09:58 PM) *
You've double-posted the same problem -- a forum no-no.
First of all, I greatly appreciate your help - thanks so much - as for my post, I said right up front that there was a previous post where the 3 scenario thing was mentioned, and I provided a link to it - so I don't think it was a case where I was trying to increase the # of views by re-posting the question (Stealthily) in a brand new, fresh post, not even referencing the original post.... also, maybe it was 'operator error,' but I couldn't get the 3 scenario thing to work - and it's not the exact same issue, it's more of a "hey, this is great, thank you all very much, but it would be even BETTERto have the 3 scenario thing - more of a don't have to have, but a 'would be nice to have' so that's why the new post - the focus on the initial post, we were done with.

QUOTE
pease download a sample table (with data) and we should be able to demonstrate the solution.


Here is the sample db, your solution with the error message, probably due to my incorrect interpretation - thanks so much for your help, I really appreciate it !

Note - you will get a couple of error messages when you open it, because I had to strip a lot of stuff out, so just hit OK a couple of times - the focus here is the q_Test_Seven_Days_Prior query

Thanks for taking a look !!!


Steve


Attached File(s)
Attached File  ProjectTracker___Copy.zip ( 386.43K ) Number of downloads: 2
 
Go to the top of the page
 
+
raskew
post Apr 13 2012, 12:34 PM
Post #14

UtterAccess Guru
Posts: 805



Hi -

Copy/paste this to a new query, then run it.

CODE
SELECT projectWorkLog.ID, projectWorkLog.ProjID, projectWorkLog.Start, Switch(DateValue([Start])=Date(),"Today " & CStr(Format(TimeValue([Start]),"hh:nn ampm")),[Start]>=Date()-7,Format([Start],"ddd hh:nn ampm"),True,Format([Start],"ddd m/d")) AS x
FROM projectWorkLog
WHERE (((projectWorkLog.Start)>#2/1/2012#))
ORDER BY projectWorkLog.Start DESC;


It should work - it worked for me.

Best wishes - Bob
Go to the top of the page
 
+
bakersburg9
post Apr 13 2012, 01:02 PM
Post #15

UtterAccess Ruler
Posts: 4,238
From: Downey, CA



bob - appreciate your help - got an error message ...... couldn't find tblWorklog - but thanks I got the answer - appreciate all your help ! (IMG:style_emoticons/default/cool.gif)
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 25th May 2013 - 02:16 AM