Results 1 to 6 of 6

Thread: new string what?

Hybrid View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    new string what?

    strNoWOCalDate = string(2-len(month(cdate(strCalDate))), "0") & month(cdate(strCalDate)) & string(2-len(day(cdate(strCalDate))), "0") & day(cdate(strCalDate)) & right(year(cdate(strCalDate)),2)


    Does anyone know what the heck the above is doing?
    I'm in the process of updating it to C# but that is classic ASP/VBScript code. I just dont quite get what its doing there.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: new string what?

    It looks to me like it's taking a String representation of a date and reformatting it into MMddyy format. If you were to take a date string like "7/4/2013" (en-AU) and feed it to that code then I think that you'd get "040713" back. There's an easy way to test that, because that code should work the same way in VB.NET just as it would in VB6 or VBScript.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: new string what?

    thanks.
    yes indeed. I thought the code would work with VB.NET as well and compare it using that. just wanted to make sure I understood what was going on rather than comparing like for like.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: new string what?

    unfortunately doing it in VB.NET does not quite work - compiler error:

    Code:
    
    Dim strCalDate As DateTime = Me.DateTimePicker1.Value
            Dim strNoWOCalDate As String = string(2-len(month(cdate(strCalDate))), "0") & month(cdate(strCalDate)) & string(2-len(day(cdate(strCalDate))), "0") & day(cdate(strCalDate)) &  right(year(cdate(strCalDate)),2)
    error: '.' expected.

    this is just before the opening bracket: = string(2-...

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: new string what?

    Does this give you the desired results?
    Code:
    Dim strCalDate As DateTime = Me.DateTimePicker1.Value
    MessageBox.Show(strCalDate.ToString("MMddyy"))

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: new string what?

    indeed. I figured it out earlier and forgot to post!
    so really, it is just MMddyy... wow... what a way to do it

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Posting Permissions

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



Click Here to Expand Forum to Full Width