April 16, 2024, 08:05:26 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Strings and integers with dates

Started by AdrianFox, January 17, 2011, 12:54:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AdrianFox

                                  I am obtaining a date from my calendar control.

                                      I convert it to a string with str$ to print it in an edit box.  Fine.

                                   But there are nulls or gaps between the date items (m, d, y).
                                  I want to convert the date to an integer that reads:
                                         1712011   (as in today's date)

   I can't simply add the integers of d,m and y of course, so I am trying to get the VAL of the string   '17 1 2011'
   To remove the spaces I am using ltrim$ first as suggested in the help.
      "VAL will stop converting digits on the first non numeric character. Use LTRIM$ on your variable to remove any leading whitespace before conversion."

  ltrim$ doesn't seem to work on this string and I still get only the first two digits.

I expect this is pretty basic but could someone just tell me what I'm missing here.

thanks.



Adrian Fox

Egil

I had a similar problem some time ago.
Here are how I did it, not excactly like yours, but maybe you'll get some ideas.
'UTCdate.eba

$include "windows.inc"

OPENCONSOLE
string dato
dato = UTC_date()

PRINT dato
PRINT
PRINT
print "---------------->  Press ESC to stop  <------------------"

do:until INKEY$ = CHR$(27)
CLOSECONSOLE
END


'
'Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨
' SUB UTC_date(),string   -   returns string of digits: YYYYMMDD
' windows.inc' must be included before calling
'
SUB UTC_date(),string
string month,day,year
SYSTEMTIME st',lt
_GetSystemTime(st)
year = STR$(st.wYear)
month = STR$(st.wMonth)
day = STR$(st.wDay)
year = RIGHT$(year,4)
month = RIGHT$(month,2)
IF VAL(month) < 10 THEN month = "0" + RIGHT$(month,1)
day = RIGHT$(day,2)
IF VAL(day) < 10 THEN day = "0" + RIGHT$(day,1)
RETURN year + month + day
ENDSUB




'UTCtime.eba

$include "windows.inc"

OPENCONSOLE
string kl
kl = UTC_time()

PRINT "The time now: " + kl + " UTC"
PRINT
PRINT
PRINT "----------->  Press ESC to stop  <-------------"

do:until INKEY$ = CHR$(27)
CLOSECONSOLE
END


'Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨Ã,¨
'   SUB UTC_time   -   returns UTC time as a string "HHMMSS"
'   "windows.inc" must be included before calling
'
SUB UTC_time(),string

string hour,mins,secs
SYSTEMTIME st
   
_GetSystemTime(st)
   
hour = STR$(st.wHour)
mins = STR$(st.wMinute)
secs = STR$(st.wSecond)

hour = RIGHT$(hour,2)
if val(hour) < 10 then hour = "0" + RIGHT$(hour,1)
mins = RIGHT$(mins,2)
if val(mins) < 10 then mins = "0" + RIGHT$(mins,1)
secs = RIGHT$(secs,2)
if val(secs) < 10 then secs = "0" + RIGHT$(secs,1)

RETURN hour + mins + secs
ENDSUB


Good luck!
Support Amateur Radio  -  Have a ham  for dinner!

billhsln

USING will also give you the results you are looking for:

DEF Fixed_Date:STRING
DEF Month, Day, Year:INT

Fixed_Date = USING("0##,Month) + USING("0##,Day) + USING("0####,Year)

The 0## makes sure that you end up with a leading 0 if number is < 10 for those with 2 digits.

Bill
When all else fails, get a bigger hammer.

AdrianFox

Thanks both Egil and Bill.  'Using' does the trick for me.

I don't know why I thought ltrim$ would remove spaces other than leading spaces... must have been one of those senior moments!
;)
Adrian Fox