Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Formatting DateTime as Date
Message
De
08/10/2008 15:08:18
 
 
À
08/10/2008 13:58:58
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows 2008 Server
Database:
Visual FoxPro
Divers
Thread ID:
01353661
Message ID:
01353677
Vues:
25
How can I format the column and the textbox so that only the date portion is displayed?

Set the ControlSource for the grid column to
( TTOD( <yAlias.MyDateField ) )
If you need a reguslar textbox to do the editing, here it is:
**************************************************
*-- Class:        txtdate 
*-- ParentClass:  textbox
Define Class txtdate As textbox
  Alignment = 3
  Value = {}
  Format = "YL"
  *-- Used to store the actual DateTime ControlSource of the control so we can enter Data Values and update the "real" datetinme controlsource manually behind the scenes
  ccontrolsource = ""
  Name = "txtdate"


  *-- Called from the Valid to update the field specified in the cControlSource property from the control's value. It expects the specified field to of data type datetime.
  Procedure updatecontrolsource
    Local ldValue, lcField, lcAlias

    ldValue = Iif( Vartype( This.Value ) = 'T', Ttod( This.Value ), This.Value )
    lcField = Justext( This.ccontrolsource )
    lcAlias = Juststem( This.ccontrolsource )

    *** Update cControlSource from the Control's Value
    If Not Empty( This.ccontrolsource )
      If Empty( Nvl( ldValue, {} ) )
        *** Check to see if we are updating a form property
        If Upper( Left( This.ccontrolsource, 4 ) ) == 'THIS'
          lcControlSource = This.ccontrolsource
          &lcControlSource = {/:}
        Else
          Replace ( lcField ) With .Null. In ( lcAlias )
        Endif
      Else
        *** make sure we have a valid date
        *** so we do not get datetime overflow errors
        *** in sql server when we attempt an update
        If Not( Upper( Left( This.ccontrolsource, 4 ) ) == 'THIS'  )
          If Between( ldValue, {^1900-01-01}, {^3000-01-01} )
            Replace ( lcField ) With Dtot( ldValue ) In ( lcAlias )
          Else
            Messagebox( 'Invalid Date', 16, 'Please Fix Your Input' )
            Return .F.
          Endif
        Else
          lcControlSource = This.ccontrolsource
          &lcControlSource = Dtot( ldValue )
        Endif
      Endif
    Endif
  Endproc


  *-- Refreshes the control's (DATE) value from the datetime value conained in the field specified in its cControlSource property
  Procedure refreshvalue
    Local ltValue

    If Not Empty( This.ccontrolsource )
      ltValue = Evaluate( This.ccontrolsource )

      *** Update the control's value from its cControlSource
      If Empty( Nvl( ltValue, {/:} ) )
        This.Value = {}
      Else
        If Vartype( ltValue ) = 'T'
          This.Value = Ttod( ltValue )
        Else
          This.Value = ltValue
        Endif
      Endif
    Else
      This.Value = {}
    Endif
  Endproc


  Procedure Init
    DoDefault()

    *** Unbind the control and save the controlsource to a special property
    If Not Empty( This.ControlSource )
      This.ccontrolsource = This.ControlSource
      This.ControlSource = ''
    Endif
    This.Format = 'D'
    This.Value = {}
  Endproc


  Procedure Valid
    If Not This.updatecontrolsource()
      Return 0
    Endif
  Endproc


  Procedure Refresh
    DoDefault()
    This.refreshvalue()
  Endproc


Enddefine
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform