Alpha Video Training
Results 1 to 11 of 11

Thread: current time in a field using field rules

  1. #1
    Member
    Real Name
    Geoff Meredith
    Join Date
    Aug 2006
    Posts
    637

    Default current time in a field using field rules

    I have a embedded browse that contains the following fields.

    User - character field
    Description - character field
    Date - date field
    Time - time field

    I have set up a field rule for the date to be automatically filled in and it works fine. Simple default expression - date().

    I tried to do this with the time field using - time() but got an error 0. I have tried various functions which return this same error which I believe is to do with the wrong data type. The now() works but this results in the date and time being shown.

    I have read through a number of posts (about 30) but cannot find a solution but there definitely seems to be a lot of confusion. I have looked at the help file but it left me even more confused. To me it seems it should be simple. You have a time field and should have a function that puts the time into it (not the date). I tried changing the field to short time but that didn't help. Some of the posts suggested using a character field and then converting to time. The downside to this if I have understood the posts correctly is that after a global update all the times will be reset to the current time. This would be a problem.

    I am hoping someone can throw some light on how to use field rules to put the current time into a field.

  2. #2
    "Certified" Alphaholic
    Real Name
    Jeff Kletrovets
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Posts
    1,135

    Default Re: current time in a field using field rules

    Try using the now() function. I have time fields and routinely populate them with it.

    Jeff

  3. #3
    Member
    Real Name
    Geoff Meredith
    Join Date
    Aug 2006
    Posts
    637

    Default Re: current time in a field using field rules

    Ok. I tried changing to a character field and it works. Can someone explain what the time field type should be used for as it doesn't seem to work with the time function. I know I am probably using it incorrectly but it doesn't seem to be very intuitive. The date() with a date field makes sense but why doesn't the time() work with a time field? I really would like to know because even though the time is now being stored using a character field I don't understand why.

  4. #4
    "Certified" Alphaholic
    Real Name
    Jeff Kletrovets
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Posts
    1,135

    Default Re: current time in a field using field rules

    Geoff

    The time field actually stores both date and time. That's why time() alone won't populate it. If you use the now() function to populate it - you can then use field formatting to display what portion of the date and time you would like. For instance, you could choose to show the field as a date, a time, or a both.

    In all of my tables I record the date and time each record was added. I choose the formatting to display it as "01-31-2007 10:18 am".

    Regards,

    Jeff

  5. #5
    Member
    Real Name
    Geoff Meredith
    Join Date
    Aug 2006
    Posts
    637

    Default Re: current time in a field using field rules

    Jeff,

    I tried the now() but it also inserts the date (see below).

    31/01/2007 03:16:43 56 pm

    All I want is the time.

    I changed the field type to character with a width of 5 and then set a simple field expression of Time("0h:0m:0s:pm"). This works but it seems odd that there is a time field type that doesn't have a function that just puts the time in. I'm hoping that I am wrong and there is a function that I've missed or I'm doing something wrong. Anyone?

    Cheers

    Geoff

  6. #6
    Member
    Real Name
    Geoff Meredith
    Join Date
    Aug 2006
    Posts
    637

    Default Re: current time in a field using field rules

    Thanks Jeff.

    I missed your second post while I was replying. I will try that.

    Geoff

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: current time in a field using field rules

    Quote Originally Posted by gmeredith17 View Post
    Ok. I tried changing to a character field and it works. Can someone explain what the time field type should be used for as it doesn't seem to work with the time function. I know I am probably using it incorrectly but it doesn't seem to be very intuitive. The date() with a date field makes sense but why doesn't the time() work with a time field? I really would like to know because even though the time is now being stored using a character field I don't understand why.
    The time() function was around long before there was a time data type and a time field type.

    it seems odd that there is a time field type that doesn't have a function that just puts the time in
    a time value without an associated date is essentially meaningless. If I ask you to meet me at 3:15 pm, you'd want to know on what date I mean, unless you assume I mean some particular day.

  8. #8
    Member trackmanpete's Avatar
    Real Name
    Pete Schuder
    Join Date
    Sep 2005
    Location
    Mansfield, MA
    Posts
    592

    Default Re: current time in a field using field rules

    Try this in your calc values:
    Code:
    clock=upper(totime(toseconds(time()),12,0))
    Also to have time run on screen you will need to go to OnTimer and do a Refresh Object for the clock.

    Hope this helps.

    Pete Schuder

  9. #9
    "Certified" Alphaholic
    Real Name
    Jeff Kletrovets
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Posts
    1,135

    Default Re: current time in a field using field rules

    Hi Geoff

    Attached is a screen shot showing how to do what you want.

    Regards,

    Jeff

  10. #10
    Member
    Real Name
    Geoff Meredith
    Join Date
    Aug 2006
    Posts
    637

    Default Re: current time in a field using field rules

    Jeff, Your solution worked a treat.

    Stan, I have the date stored in a separate field. There are situations where the date may not be important. An action may occur everyday at a certain time. The date itself is then redundant information. However, this isn't the case with my application or with most scenarios I can think of so I can appreciate the logic behind it. I do believe there should be just a time function that returns the time and I guess it would be possible to write some xbasic code to achieve this but sadly my abilities are some what wanting.

    Thank you all again for your help as I would be lost without it. Hopefully I will be able to support others in the same way one day.

  11. #11
    "Certified" Alphaholic
    Real Name
    Jeff Kletrovets
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Posts
    1,135

    Default Re: current time in a field using field rules

    Good deal Geoff! Glad I could help.

Similar Threads

  1. How to create a calculated, summary field:FIELD RULES
    By fddizon in forum Alpha Five Version 6
    Replies: 7
    Last Post: 02-03-2006, 04:43 PM
  2. current time field on form
    By Joe D in forum Alpha Five Version 6
    Replies: 11
    Last Post: 11-17-2005, 03:23 AM
  3. Browser Bug: Checkbox field does not respect field rules
    By Blake in forum Alpha Five Version 6
    Replies: 4
    Last Post: 10-06-2005, 05:11 PM
  4. field rules lookup table and field to fill
    By rleunis in forum Web Application Server v6
    Replies: 5
    Last Post: 09-22-2005, 07:33 AM
  5. Field Rules & Field Descriptive Names
    By dchiass in forum Alpha Five Version 5
    Replies: 1
    Last Post: 08-24-2004, 04:50 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •