Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Date functions in "pure" Excel


Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2006, 11:25 AM
blindwig's Avatar
blindwig blindwig is offline
Ultimate Contributor

* Expert *
 
Join Date: Jun 2003
Location: New York, NY
Posts: 1,929
Default Date functions in "pure" Excel


Hey guys, I have a question, not really in VBA, but more in "Pure" Excel -
How do I write a function to give a date on a particular day?
I'm making a sheet for my timecard and one of the fields I need to put is the Pay Period Ending Date. Our pay periods always end on a Saturday, so what I want to do is wrap the Now() function to return the date of the coming Saturday.
So if today is Saturday, I want to know today's date. If today is Friday, I want to know tomorrow's date. If today is Thursday, I want to know the date 2 days from now. Etc...
I'd prefer to do this in "pure" excel, not macros or VBA or whatever.
I started writing a set of nested IFs, then tried a lookup table, and it always got messy and started breaking. Any better ideas?

Thanks,
Mike
__________________
"Fortunately, I live in the United States of America, where we are gradually coming to understand that nothing we do is ever our fault, especially if it is really stupid." -Dave Barry
Reply With Quote
  #2  
Old 06-12-2006, 12:55 PM
Wamphyri's Avatar
Wamphyri Wamphyri is offline
Variable not defined

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
Default

Yeah, try
Code:
=NOW()+7- WEEKDAY(NOW(),1)
__________________
-Carl
Reply With Quote
  #3  
Old 06-12-2006, 01:04 PM
Peter_Aquino's Avatar
Peter_Aquino Peter_Aquino is offline
Contributor

* Expert *
 
Join Date: Sep 2004
Location: San Diego, CA, USA
Posts: 732
Default

You could also use:
Code:
=TODAY()+INDEX({6,5,4,3,2,1,0},WEEKDAY(TODAY(),1))
Reply With Quote
  #4  
Old 06-13-2006, 12:23 PM
blindwig's Avatar
blindwig blindwig is offline
Ultimate Contributor

* Expert *
 
Join Date: Jun 2003
Location: New York, NY
Posts: 1,929
Default

The WEEKDAY() function - that's just what I was looking for!
I needed a function like that to translate the day into a numerical indew for the week, and I did get the LOOKUP() function working, but of course that required using a table on a hidden sheet.

Thank you both. Both solutions worked equally well. I used Wamphyri's because it was a little shorter.

FYI, my original solution was this:
=NOW()+LOOKUP(TEXT(NOW(),"dddd"),LookUps!$A$2:$A$8,LookUps!$B$2:$B$8)
With A2-A8 being Sunday-Saturday and B2-B8 being 6-0

Thanks again!
__________________
"Fortunately, I live in the United States of America, where we are gradually coming to understand that nothing we do is ever our fault, especially if it is really stupid." -Dave Barry
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->