Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

WEEK NUMBERS

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    WEEK NUMBERS

    Anybody out there ever had the need to convert a date into a WEEK NUMBER. Not sure whether this is a UK format. For those not familiar with this term, week numbers run from 1 to 52 starting 1st January each year. Pretty obvious.
    I need to check if two order dates occur in the same week number and in the same year. Technically the change over from week 52 in one year to week 1 in the following year would not matter.
    Regards,
    Ian Stewart

    #2
    RE: WEEK NUMBERS

    You'll need to setup/build a table to contain date ranges for weeks and corresponding week numbers for a number of years into the future (decide for yourself how far into the future your application will be used).



    "week numbers run from 1 to 52 starting 1st January each year" - fine in concept but in real usage there have to be 53 weeks periodically/eventually (usually five or six or seven years) to keep the sequence in some sort of correlation to the calendar.

    Once you have the table built indicating where the fifty-third week falls, you do a lookup to that table based on the calendar date to return a week number.
    There can be only one.

    Comment


      #3
      RE: WEEK NUMBERS

      Upon reconsideration of your post, my answer is incorrect, but still pertinent.

      What do you do with the 365th day of the year? Is that week 53 in and of itself?

      The procedure would seem to be to obtain the "day of the year", a number, then divide by 7 to obtain the "raw" week number (with decimal), then get the floor() of that number.

      I'd be glad to pursue the computation of the parts involved if this is not sufficient to your needs.
      There can be only one.

      Comment


        #4
        RE: WEEK NUMBERS

        FLOOR((JDATE(DATE())-JDATE(CTOD("01/01/"+RIGHT(DTOC(DATE()),4))))/7)+1

        = 5.000000



        I've always worked with Alpha Five in some version or another. I'm assuming that floor(), jdate(), and ctod() are valid in Alpha Four.

        If you are passing a variable or field value to the expression...
        g
        FLOOR((JDATE(datevalue)-JDATE(CTOD("01/01/"+RIGHT(DTOC(datevalue),4))))/7)+1
        There can be only one.

        Comment


          #5
          RE: WEEK NUMBERS

          Stan,
          Many thanks for your efforts. Unfortunately jdate is not available in Alpha4. I am however in the process of converting my applications to Alpha5 and with the jdate function the problem is easily solved. Again many thanks
          IAN

          Comment


            #6
            RE: WEEK NUMBERS

            If this requirement is for the current year only, then a solution would be to use a CASE() funtion or a script with the CASE{} command.

            You could compare the record's date against a hard-coded list of week ending dates to give you the week number.

            This is by no means an elegent solution, but it would work.

            gm

            Comment


              #7
              RE: WEEK NUMBERS

              Thanks Gedi,
              Unfortunately there is not a case() function in Alpha4v6 although there is a case() statement in the script language.
              This whole query started off hoping their was a simple solution. It's not surprising as I did a internet search on "week numbers" and nobody seems to agree on what they are. They can't even agree what day a week starts with.
              I think Stan's solution using the jdate function in Alpha 5 will probably be the best.
              Many thanks,
              IAN

              Comment


                #8
                RE: WEEK NUMBERS

                Ian;
                Actually I believe A4V6 is the first version of A4 with the "Case" function. By the way, is "jdate" "Julian Date"? If so, I believe it would not be difficult to construct a look-up table that would take care of your needs.

                Duncan

                Comment


                  #9
                  RE: WEEK NUMBERS

                  Thanks Duncan,
                  Your right, I do have the case statement available (problem with using an old manual). Jdate apparently is a Julian date function in Alpha5 which would solve the problem (see Stan Mathews response above).
                  Thanks
                  Ian

                  Comment


                    #10
                    RE: WEEK NUMBERS

                    Stan,
                    Just to let you know I have solved my problem. I was beginning to lose sight of what I wanted to acheive, ie. checking if two dates occurred in the same week number. Since it doesn't matter what the actual week number is, 5,50,100 or whatever, I generated my own week numbers from an arbitary date (Sun 6 Jan 2002) and calculated a week number for each of the two dates to be compared.
                    I had forgotten that you can actually subtract two dates in Alpha4 which generates a number. You can't do any arithmetic calculations on this number until it is enclosed in ().
                    The code I used to generate a week number for each of the two dates is:
                    FLOOR((DATE-CTOD("6-1-2002"))/7)+1

                    Again, thanks for your help, it was the jdate idea that set me on the right track.

                    IAN

                    Comment


                      #11
                      RE: WEEK NUMBERS

                      Glad to hear it. I was just experimenting and, of course, you can subtract dates in Alpha Five as well. I had tried that early in my attempt to suggest a solution and must have had a typo in my efforts because it didn't work correctly. That's when I went to jdate().
                      There can be only one.

                      Comment


                        #12
                        RE: WEEK NUMBERS

                        This is a script that will calculate the week number. There are two versions. Script 1 needs all three lines. Script 2 is all one line. These scripts use A4 V3 functions. They assume that a week is Sunday through Saturday. There could be 53 weeks in a year.

                        Enter_Date is a date field in my table.
                        I hope this helps.

                        Stans script fails to take into account that the first day of the year is not always Sunday.



                        'Script 1****************************************

                        vndow = (dow(ctod("01-01-" + ltrim(str(year(Enter_Date))))) + 1) - dow(Enter_Date)
                        vnumber = if(vndow " 1.00,1.00,vndow)
                        ceiling((((Enter_Date) - (ctod("01-01-" + ltrim(str(year(Enter_Date)))))) + vnumber ) / 7)

                        'Script 2****************************************

                        ceiling((((Enter_Date) - (ctod("01-01-" + ltrim(str(year(Enter_Date)))))) + (if((dow(ctod("01-01-" + ltrim(str(year(Enter_Date))))) + 1) - dow(enter_date)"1.00,1.00,(dow(ctod("01-01-" + ltrim(str(year(Enter_Date))))) + 1) - dow(enter_date))) ) / 7)

                        Comment


                          #13
                          RE: WEEK NUMBERS

                          "week numbers run from 1 to 52 starting 1st January each year"

                          So "the first day of the year is not always Sunday" but it is always January 1, as the post stated.
                          There can be only one.

                          Comment


                            #14
                            RE: WEEK NUMBERS

                            Stan my apologies I misunderstood if a week starts Jan 01 and ends Jan 07 than this will work for V4 with enter_date a field in the table.

                            ceiling((((Enter_Date) - (ctod("01-01-" + ltrim(str(year(Enter_Date)))))) + 1 ) / 7)

                            Comment


                              #15
                              RE: WEEK NUMBERS

                              This might be better

                              floor((((Enter_Date) - (ctod("01-01-" + ltrim(str(year(Enter_Date)))))) ) / 7) + 1

                              Comment

                              Working...
                              X