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

inverse of ctime()

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

    inverse of ctime()

    ctime(date_time_variable) converts a date_time variabale to a character varibale so

    ctime(now()) returns

    "20100914103025909"


    what goes back the other way, ie would convert

    "20100914103025909" to a date time value ?

    basically I want to store a date time value in a character field and then retrieve it.

    Thanks

    John

    #2
    Re: inverse of ctime()

    Because the format of the character string is known you can pick off the pieces of the string and reconvert into real date and time values.

    The documention refers to then ending value of the string as "P" which is, I suppose, for am or pm but it looks like it's not valid anymore... it looks like it's just another value for seconds and that the time is being converted to a 24 hour clock. The documentation needs to be updated.

    If someone hasn't written one already I'll put one together a bit later this morning.

    Comment


      #3
      Re: inverse of ctime()

      Originally posted by Davidk View Post
      Because the format of the character string is known you can pick off the pieces of the string and reconvert into real date and time values.

      The documention refers to then ending value of the string as "P" which is, I suppose, for am or pm but it looks like it's not valid anymore... it looks like it's just another value for seconds and that the time is being converted to a 24 hour clock. The documentation needs to be updated.

      If someone hasn't written one already I'll put one together a bit later this morning.

      Thanks for this, I'm happy to do a recursive bit of chopping to do it, just wondered if there was a built in command that did it

      Ta

      John

      Comment


        #4
        Re: inverse of ctime()

        You may have figured this out already but after getting the characters turned around and separated as necessary, you can use convert_type() to change it to an actual date/time type.

        ?convert_type( "09/14/2010 10:30:25.909", "T" )
        = 09/14/2010 10:30:25 90 am

        Comment


          #5
          Re: inverse of ctime()

          Originally posted by CALocklin View Post
          You may have figured this out already but after getting the characters turned around and separated as necessary, you can use convert_type() to change it to an actual date/time type.

          ?convert_type( "09/14/2010 10:30:25.909", "T" )
          = 09/14/2010 10:30:25 90 am

          I've used

          Code:
          dim tempdatetime as T
          tempdatetime = time_var(val(left(t.my_value,4)),val(mid(t.my_value,5,2)),val(mid(t.my_value,7,2)),val(mid(t.my_value,9,2)),val(mid(t.my_value,11,2)),val(mid(t.my_value,13,5))/100)

          where t.myvalue is the field containing the output of ctime(a date time)

          time_var(year,month,day,hour,minute,second) where all the values are integers execpt seconds where it goes to 3 decimal places (xx.yyy seconds the last 5 digits of the ctime output)

          Thanks for the suggestions

          John

          Comment


            #6
            The inverse of ctime()

            Originally posted by tarlachmoorhouse View Post
            what goes back the other way, ie would convert "20100914103025909" to a date time value ?

            I think this
            Code:
            tempdatetime = eval(mask(t.my_value,"time_var(    ,  ,  ,  ,  ,  )"))

            See explanation in the IW with European time: dd-mm-yyyy
            this should work also for mm-dd-yyyy.

            Regards

            Ton
            Most things are simple but unfortunately only after the first time

            Comment


              #7
              Re: The inverse of ctime()

              Originally posted by Ton Spies View Post
              I think this
              Code:
              tempdatetime = eval(mask(t.my_value,"time_var(    ,  ,  ,  ,  ,  )"))

              See explanation in the IW with European time: dd-mm-yyyy
              this should work also for mm-dd-yyyy.

              Regards

              Ton
              Thanks Ton a much cleaner solution than my multiple mid's

              Regards

              John

              Comment


                #8
                Re: inverse of ctime()

                Hi John,

                Quick response, did you test it? Also in mm-dd-yyyy okay?

                I used to do the same way as you did -and sometimes you must - but Stan Mathews was my teacher in nesting functions to get them in one line.

                Ton
                Most things are simple but unfortunately only after the first time

                Comment


                  #9
                  Re: inverse of ctime()

                  Ton,

                  Very impressive.

                  Comment


                    #10
                    Re: inverse of ctime()

                    Learned something new - I've never used timevar() before. That's definitely easier and cleaner.

                    However - just an FYI - like so many things in programming there is a trade off. Using the simpler timevar() takes over 20 times longer than "cutting up the string" and using convert_type(). If it only needs to be done once, I'd use the timevar() method. But if you are running it in a loop that extra time may make a noticeable difference. Unfortunately there's another trade-off, the convert_type() function seems to ignore the decimals. So, you're stuck with the slower time using timevar() if the decimals are important.

                    Code:
                     
                    [COLOR=blue]'09/15/2010 21:36:10.890[/COLOR]
                    c_var = "20100915213610890"
                     
                    stime = now()
                    FOR qx = 1 to 1000
                        result = eval( mask(C_var,"time_var(    ,  ,  ,  ,  ,  .   )"))
                    NEXT
                    ui_msg_box( "TIME", "Time: " + ltrim(str(now()-stime,10,3 )) +crlf(2)+ result )
                     
                    stime = now()
                    FOR qx = 1 to 1000
                        result = convert_type( substr(c_var,5,2)+"/"+substr(c_var,7,2)+"/"+left(c_var,4)+" "+substr(c_var,9,2)+":"+substr(c_var,11,2)+":"+substr(c_var,13,2)+"."+right(c_var,3), "T" )
                    NEXT
                    ui_msg_box( "TIME", "Time: " + ltrim(str(now()-stime,10,3 )) +crlf(2)+ result )
                     
                    stime = now()
                    FOR qx = 1 to 1000
                        result = convert_type( mid(c_var,5,2)+"/"+mid(c_var,7,2)+"/"+left(c_var,4)+" "+mid(c_var,9,2)+":"+mid(c_var,11,2)+":"+mid(c_var,13,2)+"."+right(c_var,3), "T" )
                    NEXT
                    ui_msg_box( "TIME", "Time: " + ltrim(str(now()-stime,10,3 )) +crlf(2)+ result )
                     
                    [COLOR=blue]'I also decided to try this. It's somewhere between the first "timevar()" method and the last method using "mid()".[/COLOR]
                    stime = now()
                    FOR qx = 1 to 1000
                        result = time_var( val(left(c_var,4)), val(substr(c_var,5,2)), val(substr(c_var,7,2)), val(substr(c_var,9,2)), val(substr(c_var,11,2)), val(right(c_var,6)) )
                    NEXT
                    aims_msg_box( "TIME", "Time: " + ltrim(str(now()-stime,10,3 )) +crlf(2)+ result )
                    So, for speed, do it the hard way by changing the string around using substr() and convert_type() but for simplicity when there's no loop or a short loop use timevar().

                    EDIT:
                    I just realized John had used mid() instead of substr(). BIG mistake if you are running in a loop and worried about time. Just changing my equation from substr() to mid() almost makes it take as long as using timevar(). Apparently the mid() function is just a wrapper for the substr() function and wrapper functions are always much slower. (I added the "mid()" version to the code above.)

                    Comment


                      #11
                      Re: inverse of ctime()

                      Thank you Rob.
                      Made it with pleasure.


                      Hi Cal

                      Thank you for your investigations and examples.

                      Have you seen that decimals are also ignored with the time_var function?
                      They should not, but get weird when the decimals are given to the function like 10890/100.
                      However the syntax is okay, I think the function does not interpret 10890/100 as a calculation.
                      Maybe at Alpha they can see why decimals are ignored beacuse formal it's not proper.
                      I tried some varations but the differences are small so it is not important at least for me.

                      Code:
                      result = time_var(2010,09,15,21,36,10890/100)
                      ?? result
                      	15-09-2010 09:36:48 00 pm
                      result = time_var(2010,09,15,21,36,10.890)
                      ?? result
                      	15-09-2010 09:36:10 00 pm
                      result = time_var(2010,09,15,21,36,10)
                      ?? result
                      	15-09-2010 09:36:10 00 pm

                      The speed can be an issue as you said. I tried this:
                      Code:
                      stime = now()
                      FOR qx = 1 to 1000
                          Dt_result = time_var(2010,09,15,21,36,18)
                      NEXT
                      Tm_result = "Time: " + ltrim(str(now()-stime,10,3 ))
                      ?? Tm_result
                      	"Time: 2.472"
                      ?? Dt_result
                      	15-09-2010 09:36:18 00 pm

                      So time_var is a time consuming function.
                      I did not look at that function for speed did not know that but for ease.

                      Well, you know the diffence between our cultures with date, decimal and currency signs
                      So with this line I have to replace mm-dd to dd-mm and "/ " to "-".

                      ?? convert_type( substr(c_var,7,2)+"-"+substr(c_var,5,2)+"-"+left(c_var,4)+" "+substr(c_var,9,2)+":"+substr(c_var,11,2)+":"+substr(c_var,13,2)+"."+right(c_var,3), "T" )
                      and when you make a mistake there is no output and no warning. Try it with this line above in the IW.

                      Therefore I constructed this one-line-statement - see post #6 - as useful for international usage.

                      Ton
                      Most things are simple but unfortunately only after the first time

                      Comment


                        #12
                        Re: inverse of ctime()

                        I haven't timed it, but another way to parse it up is as follows:
                        Code:
                        cTm = "20100914103025909"
                        cTm2 = mask(cTm,"    -  -  -  -  -  -   ")
                        
                        ?cTm2
                        = "2010-09-14-10-30-25-909"
                        
                        ?tagged_pattern("1-2-3-4-5-6-7","2/3/1 4:5:6 7",cTm2)
                        = "09/14/2010 10:30:25 909"
                        The mask() and tagged_pattern() could be combined for a single expression.

                        Steve

                        Comment


                          #13
                          Re: inverse of ctime()

                          Originally posted by Ton Spies View Post
                          ...and when you make a mistake ...
                          Yeah, that happened to me once, too.:D

                          Comment


                            #14
                            Re: inverse of ctime()

                            Originally posted by Steve Andrews View Post
                            The mask() and tagged_pattern() could be combined for a single expression.
                            Hi Steve,

                            Thank you for your contribution because with a fabulous time this now is the quickest and thus far best solution as inverse of ctime(). (Speedtime tested like Cal' way so without the dim's = 0.055!)

                            Dim C_var as C = ctime(now())
                            Dim T_result as T = convert_type(tagged_pattern("1-2-3-4-5-6-7","3-2-1 4:5:6 7",mask(C_var," - - - - - - ")) , "T" ) ' for dd-mm-yyyy OR
                            Dim T_result as T = convert_type(tagged_pattern("1-2-3-4-5-6-7","2/3/1 4:5:6 7",mask(C_var," - - - - - - ")) , "T" ) ' for mm/dd/yyyy


                            Originally posted by CALocklin View Post
                            Unfortunately there's another trade-off, the convert_type() function seems to ignore the decimals. So, you're stuck with the slower time using timevar() if the decimals are important.
                            Hi Cal,

                            Please note that there are 3 decimals (for tag7) but to get proper results, use only the first 2.
                            So ignore the last position of the string when created by the ctime function. (As shown above)

                            I also had problems with the decimals in the time_var function (only non US) but Selwyn fixed that for the next release.
                            So as far I know our decimals-problem has gone then.

                            Ton
                            Last edited by Ton Spies; 09-18-2010, 06:40 AM. Reason: added tested speedtime
                            Most things are simple but unfortunately only after the first time

                            Comment


                              #15
                              Re: inverse of ctime()

                              As the original poster I've been following this with interested, but as I simply use this to load and save globals variables to a table when the programme loads and at other time, I wasn't to worried about the speed of operation.

                              However Tom's last post made me realise that we may have a problem as my solutions don't take into account that the UK / US date format issue, ie mm/dd/yyyy and dd/mm/yyyy.

                              I'm just wondering if there is a better solution than using ctime to my over all problem, I want to convert a datetime variable to a character format so I can save it in a character field, and then 're-constitute' it into a datetime variable at a later time.

                              I looking at whether it might be better to to use one conversion to re-convert the date part which would deal with the internationaisation of it, and a second re-conversion to handle the time part and then combine them into the datetime.

                              Ta

                              John

                              Comment

                              Working...
                              X