Formula for date field to display only first day of each week?

  • 0
  • 1
  • Question
  • Updated 3 years ago
  • Answered

I am not skilled with php but I am learning. Thank you in advance for your patience.

I'm interested in a formula that will display only dates that are the first day of the week in the date field. E.g. rather than letting the user choose from January 1, 2014, January 2, 2014, January 3, 2014, etc. I would like them to have only choices like, January 5, 2014, January 12, 2014 (Sunday is our first day of the week),...February 2, 2014 and so on.

I tried FirstDayOfWeek but apparently I am not using it properly. I want them to be able to choose from dates so they can enter previous weeks if necessary.

Thanks for any tips you may have.

Photo of Elizabeth

Elizabeth

  • 0 Points

Posted 5 years ago

  • 0
  • 1
I would just skip the whole php idea and simply use excel to create a table of all the Sundays for the next 10 years and load them into a table. Make that date the Key field of the table.



Then make a relationship back to your data entry table and the users will see a drop down list of only Sundays. if you like you can create a report to be used on your FORM properties to limit the dates the user will be able to choose from - for example perhaps only Sundays going back or forward 6 months.
Photo of Elizabeth

Elizabeth

  • 0 Points
Thanks for your quick reply! I did think of that but I was hoping for a more elegant solution that strengthened my PHP abilities. I will definitely keep this in mind as an option before I stay up too late, though. Mark Shnier's advice will be taken at about 10:45 p.m. PDT. :)

One more reason for using code--

I thought using PHP would allow me to relate the dates available to the year the user was in--so for example, in 2014, the user would see all FirstDayOfWeek[(Date)] or something. But that code gives me only the first day of the week for the week the user enters data. We travel so there's a fair chance of back-entry.

I don't have a problem limiting them to a list that I enter personally.
Well, since I posted my answer as an answer, it will no longer be unanswered.  You may need to post it again to get other users here to see that its still looking for an answer.
Photo of Elizabeth

Elizabeth

  • 0 Points
Oh. Darn. Do you think I should abandon PHP in this case because it's a pain to learn, or because, as someone who knows how to use it, you can't think of a nice line of code that would do that? I don't want to spend a lot of time on novel code, but I'm happy to put in a little effort for a prettier structure.
I don't know any PHP so I can't help you.  You would probably have to capture Dan Dielbot's attention and then get into the whole image Onload technique.
Photo of Elizabeth

Elizabeth

  • 0 Points
Thanks for the tip. I will do that when refining the database. Since the dates should be compatible with those I enter by hand, and anyway it will only be a few to re-enter since we are small, I'll go ahead with the handwritten solution and keep this thread handy for when I go back to make it nicer.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
>capture Dan Dielbot's attention

My robot picked up this reference to my name so you got my attention.

Why involve PHP? This is a simple thing to accomplish. The jQuery datepicker UI (which QuickBase uses) is highly configurable. All you have to do is inject a little script into the page using the image onload technique and use this tiny bit of code to allow only Sundays to be selectable:

Pastie Database

https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=257


Note that QuickBase has already initialized the datepicker so you have to use the option parameter to reconfigure it to your Sunday only needs.

See the screenshot attached.

ProTip: Use JavaScript for everything! Don't even bother asking about other technologies - JavaScript will solve all your QuickBase problems. I can't wait till ES6 lands in 2014.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,434 Points 20k badge 2x thumb
>Do you think I should abandon PHP

You will get vastly more results out of learning and using JavaScript with QuickBase. You really don't want to use any third party web server technology unless the entire goal is to tightly integrate QuickBase with your web site. Moreover, adding your web site into your QuickBase workflow only creates a new point of failure.
Photo of Allison

Allison

  • 0 Points
Hi Dan, I would like to use this type of solution for a similar situation. However, instead of returning Sunday's, I'd like the calendar to only return dates that fall or between two dates listed in other fields.  i.e. The event runs from 1/4 to 1/7 and for this daily report the date is 1/6.  I don't want my user to be able to choose 1/8.  Appreciate your help!