Jump to content

Ideas to help simplify?


Recommended Posts

This works just fine, so unless someone has an idea to simplify this, I'm fine with it in my script. I've just noticed that I tend to do things the hard way, and it'd be nice to see ideas of simplifying, so someday I'll get used to it and do things the easy way naturally.

anyway, cutting to the chase, here's *my* way of doing this (I want to take the date 3 weeks from _NowCalcDate() and change the format to 2-digit day followed by 3-letter month, ie 24Oct)

#include <Date.au3>

$date1 = _DateTimeFormat(_NowCalcDate(),1) ;Get today's date
$remove_left = StringInStr($date1,",")           ;how much to take from left to remove the day
$date2 = StringTrimLeft($date1, $remove_left + 1);remove the day of the week
$date_mo = StringLeft($date2, 3)                    ;Grab the 1st 3 letters of the month
$date3 = StringTrimRight($date2, 6)             ;remove the year
$date_day = StringRight($date3, 2)               ;grab the 2-digit date
$date = $date_day & $date_mo                      ; put the two together
MsgBox( 4096, "MY Short Format", $date)
Thanks in advance for any ideas! Edited by falconv
Link to comment
Share on other sites

This works just fine, so unless someone has an idea to simplify this, I'm fine with it in my script. I've just noticed that I tend to do things the hard way, and it'd be nice to see ideas of simplifying, so someday I'll get used to it and do things the easy way naturally.

anyway, cutting to the chase, here's *my* way of doing this (I want to take the date 3 weeks from _NowCalcDate() and change the format to 2-digit day followed by 3-letter month, ie 24Oct)

#include <Date.au3>

$date1 = _DateTimeFormat(_NowCalcDate(),1);Get today's date
$remove_left = StringInStr($date1,",")         ;how much to take from left to remove the day
$date2 = StringTrimLeft($date1, $remove_left + 1);remove the day of the week
$date_mo = StringLeft($date2, 3)                  ;Grab the 1st 3 letters of the month
$date3 = StringTrimRight($date2, 6)           ;remove the year
$date_day = StringRight($date3, 2)             ;grab the 2-digit date
$date = $date_day & $date_mo                    ; put the two together
MsgBox( 4096, "MY Short Format", $date)
Thanks in advance for any ideas!
I am not sure that your script does what you describe. When I run it I get a msgbox with "be4 O".

Edit

I now have it with the correct date format but not the 3 week part.

#include <Date.au3>

$date1 = _DateTimeFormat(_NowCalcDate(),1);Get today's date
$remove_left = StringInStr($date1,",");how much to take from left to remove the day
$date2 = StringTrimLeft($date1, $remove_left + 3);remove the day of the week
$date_mo = StringLeft($date2, 3);Grab the 1st 3 letters of the month
$date3 = StringTrimRight($date2, 6);remove the year
$date_day = StringRight($date1, 2);grab the 2-digit date
$date = $date_day & $date_mo; put the two together
MsgBox( 4096, "MY Short Format", $date)
Edited by BigDod


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

@BigDod - It uses your system's settings for "Long Date Format", so if you're not using "Tuesday, October 04, 2005" format it won't come out right because it'd be chopping off the wrong parts when it uses StringLeft and such (you can use MsgBox(4096, "Pc Long format", _DateTimeFormat( _NowCalc(),1)) to see what your long date format is set as. don't forget to include Date.au3)

@JdeB - Sweet, thank you!! That's ingenious! :P I hope soon I'll know AutoIt well enough to come up with something like that the 1st time ;) Now to check to make sure it will work with _DateAdd 3 weeks

@vollyman - maybe you put it in wrong? I tried it and it came out "04Oct" now I just need to figure out how to get it to say "25Oct" on the 4th, and "01Nov" on the 11th, etc.

Edited by falconv
Link to comment
Share on other sites

  • Developers

I hope soon I'll know AutoIt well enough to come up with something like that the 1st time ;) Now to check to make sure it will work with _DateAdd 3 weeks

#include<date.au3>

Dim $tdate,$ttime

$tdate = _DateAdd("w",3,_NowCalcDate())

$tMM = StringMid($tdate,6,2)

$tdd = StringMid($tdate,9,2)

$Fdate = $tdd & _DateMonthOfYear($tmm, 1)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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...