Get Stuff(ed): formatted Datetime string

ETA: 2009.12.02: This code is in version 8. As the inimitable Doug Hennig (fangirl squeal) points out in comments, VFP 9 TTOC() has a new flag for returning an XML DateTime format. I would still use one of the options below because they are version-neutral, and because Set Date Short | Long affects the return value (the setting from Windows Control Panel is used).

Well, that and because sometimes one simply must write code that makes one giggle.


Silly, but this code amuses me.

? Stuff( ;
  Stuff( ;
  Stuff( ;
  Stuff( ;
  Stuff( Ttoc( Datetime(), 1 ), 13, 0, ':'), ;
  11, 0, ':'), ;
  9, 0, ' '), ;
  7, 0, '.'), ;
  5, 0, '.')

ETA (2009.12.02): Another way to do the same thing as above is the following:

?Transform( Year( Date() ) ) + "." + ;
  Padl( Transform( Month( Date() ) ), 2, "0" ) + "." + ;
  Padl(Transform( Day( Date() ) ), 2, "0" ) + " " + ;
  Padl(Transform( Hour( Datetime() ) ), 2, "0" ) + "." + ;
  Padl(Transform( Minute( Datetime() ) ), 2, "0" )+ "." + ;
  Padl(Transform( Sec( Datetime() ) ), 2, "0" )

*Yawn*

Advertisements

6 thoughts on “Get Stuff(ed): formatted Datetime string

  1. OMG! Where did you find that code? I’ve had some similar strange experiences when I’m refactoring some customer’s codes, but that one topped it. Isn’t it strange what people can come up with, instead of just pressing F1 and search for the correct function to use….

  2. Shouldn’t there a T in the first code ?

    ? Stuff( ;
      Stuff( ;
      Stuff( ;
      Stuff( ;
      Stuff( Ttoc( Datetime(), 1 ), 13, 0, ':'), ;
      11, 0, ':'), ;
      9, 0, 'T'), ;
      7, 0, '.'), ;
      5, 0, '.')
    

    I like this better

    ?transf(ttoc(datetime(),1), '@R ####-##-##T##:##:##')
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s