Jump to content

StringFormat


LurchMan
 Share

Recommended Posts

Hey everyone -

I'm trying to take a string like such: 20080125071800 and turn it into 2008/01/25 07:18:00. The only problem is I'm horrible with StringFormat. Any help is appreciated, and possibly anywhere that might simplify this for next time.

Thanks

Lurch

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Thank you! RegEx is still way above my level but maybe some day.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

Here's a worse way to do it :x

$string = 20080125071800

$split = StringSplit ($string , "" , 2)

$new = $split[0] & $split[1] & $split[2] & $split[3] & "/" & $split[4] & $split[5] & "/" & $split[6] & $split[7] & " " & $split[8] & $split[9] & ":" & $split[10] & $split[11] & ":" & $split[12] & $split[13]

msgbox (0, '' , $new)

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

.... I'm horrible with StringFormat. ....

Here is a couple of better or worst methods (ways) StringFormat orientated.

$string = 20080125071800

$sNewString = StringLeft($string, 4) & "/" & StringMid($string, 5, 2) & "/" & StringMid($string, 7, 2) & " " & _
        StringMid($string, 9, 2) & ":" & StringMid($string, 11, 2) & ":" & StringRight($string, 2)
; Or

$sNewStringFormat = StringFormat("%04d/%02d/%02d %02d:%02d:%02d", StringLeft($string, 4), StringMid($string, 5, 2), _
        StringMid($string, 7, 2), StringMid($string, 9, 2), StringMid($string, 11, 2), StringRight($string, 2))

MsgBox(0, 'Result', "$sNewString            = " & @TAB & $sNewString & @CRLF & "$sNewStringFormat = " & @TAB & $sNewStringFormat)

;Results
;2008/01/25 07:18:00
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...