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 TIME to DATE, or other way around

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

    Converting TIME to DATE, or other way around

    On a form I have a variable that has a control type of "Radio Button". The radio buttons select the choices and assign a number value to the variable.

    In a script I am looking at the variables numeric value and then assigning other variables values to a query search. This is almost exactly like the example in Alpha Sport.

    Two of the options assign date values that are queried against a "Date" filed in the table. This works like a champ.

    The problem I am having is I also want to be able to query a date against a "Time" field, just looking at the "Date" part of the time field. If that makes sense.

    In the table I have Date field, Date,D,8,0 that contains the date an invoice was created.

    Then there is a Time field, tmsart,T,17,0 that contains the date and time the job is scheduled to be printed. In the query I need to be able to only search against the date part of the time field.

    Here is my code.

    Code:
    if Options = 1 then 'Show invoices by Date
    	filter =  "date = [varD->today]"
    else if Options = 2 then 'Show invoices by range of dates
    	filter = "between(date,[varD->begindate],[varD->enddate])"
    else if Options = 3 then 'Show invoices by schedule date
    	filter =  "tmstart = [varD->today]"	
    else if Options = 4 then 'Show invoices by range of scheduled dates
    	filter = "between(tmstart,[varD->begindate],[varD->enddate])"	
    else if Options = 5 then 'Show All invoices
    	topparent.queryrun("invoice = .t.","tmstart","","No","Wo_Header",.f.)		
    	goto DONE
    end if 
    
    dim typefilter as c
    if Options2 = 1 then
     typefilter = "invoice=.T..AND.exported=.T..AND.export_it=.T."
     else if Options2 = 2 then
     typefilter = "invoice=.T..AND.export_it=.T..AND.EXPORTED=.F."
     else if Options2 = 3 then
     typefilter = "invoice=.T."
     else if Options2 = 4 then
     typefilter = "invoice=.T..AND.exported=.F..AND.EXPORT_IT=.F."
     end if
    typefilter = filter+".AND."+typefilter 
     
    'substitute the parameters in the filter expression
    typefilter = replace_parameters(showfilter,local_variables())
    
    topparent.queryrun(typefilter,"tmstart","","no","Wo_Header",.T.)'Run query
    
    DONE:
    Thanks..

    #2
    Re: Converting TIME to DATE, or other way around

    ? time("MM/dd/yyyy",now())
    = "09/01/2015"
    ? time("MM/dd/yyyy",now()) = dtoc(date())
    = .T.

    Substitute your time field for now() and your date field for date().
    There can be only one.

    Comment


      #3
      Re: Converting TIME to DATE, or other way around

      filter = "time("MM/dd/yyyy",Tmstart) = [varD->today]" throws errors as I assume there are quotation marks within quotation marks.

      What I may need to do is convert the time field to a date field in the table and the query against that.

      Comment


        #4
        Re: Converting TIME to DATE, or other way around

        It throws errors because you have quotes within quotes.

        filter = "time(\"MM/dd/yyyy\",Tmstart) = dtoc([varD->today])"

        If I'm reading it right.


        Note:

        filter = "time("MM/dd/yyyy",Tmstart)

        start reading from the first double quote. When you come to the second, the string ends (for Alpha) unless you escape it.
        There can be only one.

        Comment


          #5
          Re: Converting TIME to DATE, or other way around

          Ok better but no cigar yet.

          When replace_parameters(showfilter,local_variables()) is run the results are "tmstart = {09/01/2015}.AND.invoice=.T..AND.export_it=.T..AND.EXPORTED=.F." which will not work in the query.

          Comment


            #6
            Re: Converting TIME to DATE, or other way around

            Don't see that here.

            dim today as D
            today = date()

            filter = "time(\"MM/dd/yyyy\",Tmstart) = dtoc([varD->today])"

            ? replace_parameters(filter,local_variables())
            = time("MM/dd/yyyy",Tmstart) = dtoc({09/01/2015})

            tmstart = now()
            ? time("MM/dd/yyyy",Tmstart) = dtoc({09/01/2015})
            = .T.
            Last edited by Stan Mathews; 09-01-2015, 03:07 PM.
            There can be only one.

            Comment


              #7
              Re: Converting TIME to DATE, or other way around

              Here is what I think is the problem.

              The filter = "time(\"MM/dd/yyyy\",Tmstart) = dtoc([varD->today])" converts the Time format to a character Date format which when queried against a Time field will always not find any matching results because the Time field in the table still contains the hours/minutes and seconds.

              So I have added two fields to the table to try to convert the tmstart field into a date only field that I can then query against. I have gotten it to convert to a character format using CDATE(TMSTART) which results in something like "20150901" which will never match anything in the [varD->today] option variable.

              Trying to convert the field value of "20150901" back into a date using CTOD() results in nul.

              Still trying things.
              Last edited by preston2; 09-01-2015, 03:20 PM.

              Comment


                #8
                Re: Converting TIME to DATE, or other way around

                converts the Time format to a character Date format which when queried against a Time field
                time(\"MM/dd/yyyy\",Tmstart) converts the time field (tmstart) to a character date value and dtoc([varD->today]) converts a date value to a character date value. The filter = "time(\"MM/dd/yyyy\",Tmstart) = dtoc([varD->today])" should compare those character values.

                ? ctod("20150901")
                = { / / }

                ? stod("20150901")
                = {09/01/2015}
                There can be only one.

                Comment


                  #9
                  Re: Converting TIME to DATE, or other way around

                  I already tried the STOD() in a calculated field rule and it says it is a invalid or incomplete expression

                  the Field Sch_datec has CDATE(TMSTART) = 20150901

                  The field Sch_date will not accept STOD(SCH_DATEC)

                  Comment


                    #10
                    Re: Converting TIME to DATE, or other way around

                    STOD() fails if the SCH_DATEC is ever blank or invalid.

                    http://www.alphasoftware.com/alphafo...or-*if_error()

                    In such cases you can use

                    *if_error(STOD(SCH_DATEC) ,{})
                    There can be only one.

                    Comment


                      #11
                      Re: Converting TIME to DATE, or other way around

                      I get a "Cannot use function in this context".

                      The SCH_DATEC field is not blank so it cannot be what is causing the "invalid or incomplete expression"

                      If I take the actual value of Sch_datec and use it like STOD("20150901") it works but that does not do me any good as the value changes.

                      I may be wrong but the way I see it is the only way to run a query using just the date part of a time field is to have that value stored as a date in a table field and so far I have not found a way to do that.

                      I may just have to change the options variable to use a time field to query against a time field but that complicates things for the end user that only want to see scheduled items for a date or date range and could care less about the time of day it is scheduled.

                      Comment


                        #12
                        Re: Converting TIME to DATE, or other way around

                        Time to attach a sample table.
                        There can be only one.

                        Comment


                          #13
                          Re: Converting TIME to DATE, or other way around

                          Originally posted by Stan Mathews View Post
                          Time to attach a sample table.
                          I am going to try and do the conversion in a script instead of using table field rules. If that does not work I will create a sample table and form.

                          Comment


                            #14
                            Re: Converting TIME to DATE, or other way around

                            Not sure what is the variable you are using in the filter to test against the time filed.
                            Assuming it's "today"
                            Let's call it v_today instead.
                            For a starter, it has to be dimmed as shared at minimum if not global depending on where you are running this script from
                            So, your script will look like this:
                            Code:
                            dim global v_today as d
                            filter="ctod(dtoc(Tmstart))=var->v_today"

                            Comment


                              #15
                              Re: Converting TIME to DATE, or other way around

                              Looks like I may have it working in a script.

                              I found that after I got the character date value from the tmstart field into the sch_datec field I needed to do an alltrim on it.

                              What I have working is being run in a script when they set the scheduling start time. It now takes the date part of the start time and stores the date part in a date field that can be used for the query.

                              Now to do the date range code and make sure it works and then it looks like I have it. I am not even going to try and see if I can make it work with field rules and the alltrim as I seem to be on the right track doing it in a script.


                              As always, thank you very much for your assistance Stan.

                              Comment

                              Working...
                              X