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

Converting character to a date field?

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

    Converting character to a date field?

    Code:
    Is it possible to convert a character field which has
    dates listed,e.g., like 4.99, 3.98, 11.95 to a date field
    like the default shows?  Keeping the month and year as it
    now stands?
         I wish to do this so I can append them to a current
    table with their dates secured in the right format. I don't
    mind inserting any day for middle choice to get right format
    of _/__/__.
         Thanks
    Howard Berg

    #2
    RE: Converting character to a date field?

    Howard:

    Check out the CTOD function. CTOD stands for character to date. For example, ctod("12/12/95") would yield a date. So the character expression "4.99" could be reformatted and then transformed with ctod.

    This is the logic:
    input="4.99"
    datestr=left(input,1)+chr(47)+"1"+chr(47)+right(input,2)
    resultdate=ctod(datestr)

    Chr(47) is the backslash and I wrote it this way because the board eats backslashes. You could just as well use the backslash itself.

    I would write a custom function it I had much of this to do.

    Hope this gets you going.

    Bill
    Bill Hanigsberg

    Comment


      #3
      RE: Converting character to a date field?

      Here's an improvement on Bill's idea to take care of months with either 1 or 2 digits:

      input="4.99"

      datestr=subst(input,1, at(".",input)-1 ) +"\01\"+ right(input,2)
      resultdate = ctod(datestr)

      (How'd I do them thar backslashes? e-mail me to find out!)

      Comment


        #4
        RE: Converting character to a date field?

        What was I thinking? They should be forward slashes anyway! (I also added color to one part of the expression just for clarification.)

        datestr = subst(input,1, at(".",input)-1 ) + "/01/" + right(input,2)
        resultdate = ctod(datestr)

        Comment


          #5
          RE: Converting character to a date field?

          I can't get anything right tonight! Left out the "r" in "substr". (If anything else is wrong you'll have to find it yourself!)

          datestr = substr(input,1, at(".",input)-1 ) + "/01/" + right(input,2)
          resultdate = ctod(datestr)

          Comment


            #6
            RE: Converting character to a date field?

            Hi Cal,

            You're not the only one who was tired last night. All the while I was talking about backslashes I was writing forward slashes!

            All the best,
            Bill
            Bill Hanigsberg

            Comment


              #7
              RE: Converting character to a date field?

              Code:
              William & Cal,
               Thanks VERY much. This will get me going.
              Nice to be pointed in the right direction.
              I knew of "CDOT"; but did know what exactly
              to do with it. Especially since converting
              from characters like "4.99" etc. which are not
              in proper form yet.
                 I'll go to work on it and learn thereby.
              Thx
              Howard

              Comment


                #8
                RE: Converting character to a date field?

                Code:
                I've enjoyed learning from all the help how "substr","cdot" and "at" will go and change the character string "." which
                populates my one field and change it to date data. Very cool!
                
                datestr = substr(input,1, at(".",input)-1 ) + "/01/" + right(input,2)
                resultdate = ctod(datestr) 
                
                Now how does one [b]launch[/b] it or start it on its way to search and change the whole field? By writing it all the way as a script? And will that change the restructuring for the field for future entries or do I do that later?
                
                I assume "input" is the name of my field:  "Last_in" ?
                
                Thx.
                Pupil # 34
                
                Howard Berg

                Comment


                  #9
                  RE: Converting character to a date field?

                  A cautious way would be to create a new empty table to hold your unique value from the table where the "bad" date data resides and a field to contain the new date value. Then do a post operation posting the unique value as is and your "expression"

                  resultdate = ctod(substr(input,1, at(".",input)-1 ) + "/01/" + right(input,2))

                  to the date value field. Verify that you are satisfied with the results, edit the structure of the oiginal table to accept the date field value by redefining the original field or adding a new field, then post the dates back to the original table.
                  There can be only one.

                  Comment


                    #10
                    RE: Converting character to a date field?

                    The ultimate caution - MAKE A BACKUP!

                    Another way to update it...
                    - Add a new date field to your current table.
                    - Use the expression above (substr(input.... ) as the definition for an Update operation where "input" is the name of your current field.
                    - Hint: make sure you don't have an active query or filtered index when you run the update.
                    - When you're SURE the new dates are correct, delete the old field. (And, keep the backup for a year or so just in case!)

                    This avoids the need to worry about posting (and what to use for the unique field) and it still protects your data because you don't change anything but the new field which was originally blank anyway. Besides, if you really goof, you've got a backup!

                    Comment


                      #11
                      RE: Converting character to a date field?

                      Code:
                      Yes, the BACKUP I have done because of the importance of these records; already saved my bacon when I initially just changed the field in question to a date field and lost all the material in the field, despite the warning message given. So I've learned the value of backing up.
                      
                      So then I came to the forum. Only pose the questions after reading the manuals and trying a few other ways. That way I
                      retain what I learn about this awesome program.
                      
                      Appreciate your suggestions. 
                      
                      Howard

                      Comment


                        #12
                        RE: Converting character to a date field?

                        Code:
                        I've added a new date field to my table and set-up an update operation using the expression
                        
                        ctod(substr(input,1, at(".",input)-1 ) + "/01/" + right(input,2)) 
                        
                        
                        but all the year dates come out 2000, instead of keeping the correct year from the "." string which show as "4.95"
                        or "12.97", eg. 
                        Should not the expression be returning them? Which is the goal of the execise?
                        Howard Berg

                        Comment


                          #13
                          RE: Converting character to a date field?

                          Howard,

                          Just did this in the code editor, interactive tab:

                          input = "3.97"
                          ? ctod(substr(input,1, at(".",input)-1 ) + "/01/" + right(input,2))
                          = {03/01/1997}

                          Got the expected result. Then put in

                          input = "3.97 " (trailing spaces) and got

                          ? ctod(substr(input,1, at(".",input)-1 ) + "/01/" + right(input,2))
                          = {03/01/2000}

                          You need to trim the spaces in your text field "input". I prefer ALLTRIM(input)

                          ctod(substr(ALLTRIM(input),1, at(".",ALLTRIM(input))-1 ) + "/01/" + right(ALLTRIM(input),2)) .

                          Good luck.
                          There can be only one.

                          Comment


                            #14
                            RE: Converting character to a date field?

                            Howard,
                            A small thing. Can you post your messages in single space?

                            Comment


                              #15
                              RE: Converting character to a date field?











                              Stan,Using Alltrim worked for sure, just as you suggested.
                              What a nice lesson in learning about "cdot","substr", "at", and
                              "Alltrim". For many of us new to A5 examples like this and others on
                              the board are of serious importance. Now that I finally got my
                              printed copy of XBasic Ref. Manual I'll be able to read further.
                              Thanks again to you, and Cal and Bill for the help.
                              Howard

                              Comment

                              Working...
                              X