Results 1 to 4 of 4

Thread: Formating date/time

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    105

    Formating date/time

    Hi
    I can't seem to get this date/time formated, i've been mucking around with it for a while and i keep getting an error saying invalide .ToAODate format

    Can anyone help? this is the text i need to format' its a string:...

    200404261726

    Its in: year/month/day/time I want to show it as 26/04/2004 17:26

    Thanks

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Where data is a string containing your value...

    VB Code:
    1. dim x as datetime = new datetime(data.substring(0,4), data.substring(4,2), data.substring(6, 2), data.substring(8,2), data.substring(10,2), 0)
    2.  
    3. msgbox(x.tostring("g"))

    I've not tested it but see what happens.
    I don't live here any more.

  3. #3
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682
    Here, I've wrapped it for you...

    VB Code:
    1. function RectifyDate(ugly as string) as string
    2.  
    3. dim x as datetime = new datetime(ugly.substring(0,4), ugly.substring(4,2), ugly.substring(6, 2), ugly.substring(8,2), ugly.substring(10,2), 0)
    4.  
    5. return x.tostring("g")
    6.  
    7. end function

    Using a DateTime object will help in validating the data too. If the date is invalid then you'll get an exception

    There are other ways to do it but this is neater and safer.
    I don't live here any more.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2002
    Posts
    105
    Thank you wossname. I was getting tired of looking at it.
    I did try using .DateTime, i forget what the error that was coming up with it.

    I'll check it out and see if it works ok.

    (ugly as string) lol, your right about that. I have no idea why they stored it like that.

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