How to remove time from date time in VB6 - vb6

i am currently working with VB6, and i have this value of date that is like this:
2022-02-26T12:06:10+02:00
I followed this url too
VB6: How to remove the Time part from Date type
but doesnt work especially the last one still shows the date as
2022-02-26T12:06:10+02:00
This is my code
Dim tdate As String
tdate = format$("2022-02-26T12:06:10+02:00" , "m/d/yyyy")
and the output is still 2022-02-26T12:06:10+02:00

Your input is a string in ISO8601 format. As its a string in a fixed format the easiest way is to just chop off the first 10 characters.
isoDateTimeString = "2022-02-26T12:06:10+02:00"
To get the date part as another string:
Dim dateAsString As String
dateAsString = Left$(isoDateTimeString, 10)
'// for 2022-02-26
Or to get it as a Date type:
Dim dateAsDateType As Date
dateAsDateType = CDate(Left$(isoDateTimeString, 10))
'// for 26/02/2022 (or whatever your locale format is)

In VB6 I've always found that the easiest way to deal with time/date values is to cast them as a Double (simply declare a variable as type Double, then assign the value from whatever source). Then, simply deal with either the integer part (days) or the fractional part (fractional days). For example, seconds are just TimeStamp/86400.0, etc. When a variable is declared as Date, it's actually stored as a Double, so I just use that as my basic TimeStamp type. VB is pretty good about re-formatting into a time/date string when printing, and it makes time-based calculations really straight-forward.

Related

Alteryx Convert String to Time

I have a column of times in ALteryx like the following:
Time
=====
8:05 AM
8:07 AM
8:11 AM
8:12 AM
8:16 AM
...
They are currently stored as a String, but I want to convert them to the Time format. So far, I have tried using the LEFT and TRIM function to isolate the time itself as such:
Trim(Left([Time], 5)," ")
However, when I try to convert this to a Time datatype, I receive type conversion errors. How can I convert something like 8:46 AM from a String to a Time datatype in Alteryx?
I did some more digging and trying different things out, and I was able to figure it out. For the reference of others, here is what I did:
DateTimeParse([VisitTime] + " " + [PartofDay],"%I:%M %P")
Where [VisitTime] is the time expressed like 8:30 and [PartofDay] is AM or PM.
After this, I used a Select tile to change the datatype from String to Time without type conversion errors.

ZEN : Allow multiple date formats in a dateText control and converting them to the YYYY-MM-DD

There is a finite list of date formats that users want to use to enter a date in a form. These formats include single digits for month and day and double digits for year. The field is represented by a dateText control.
How would one get to allow a dateText control to accept multiple date formats ? I see only 3 listed (https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GZCP_forms_dateText), do those include using single digits for month and day ?
I tried to set the value of format = "#(myPageProperty.myValue)# " but I got a compilation error in Studio so that went nowhere. Has anyone ever been able to set the format value depending on the user input value?
I am guessing that the control input value must be converted to the YYYY-MM-DD before validation. I am open to calling a javascript function to do that but where would be the best place to put it?
for details see Class %ZEN.Component.dateText
setting format:
Property format As %ZEN.Datatype.string(MAXLEN = 3, **VALUELIST = ",MDY,DMY,YMD",** ZENEXPRESSION = 1)
you have exactly 3 formats or ""
Your guess on values is correct and documented:
/// The value of this control is always in the canonical form: YYYY-MM-DD
As this is one of the oldest components of ZEN your only chance to achieve
your way of operation is to create your own version inheriting from
Class %ZEN.Component.dateText and overloading the parts you want to change

Qtp add more than 15 strings or convert more than 15 strings

Can someone please guide me on how to convert more than 6 characters into int? Because I need to do sum after convert to int. I tried so many ways like CInt, CLng, etc still throw exponential value.
Stroutput = 2018050302216556
Sum = Stroutput + 1
I tried to divide into sveral chuck using right function but it doesnt look good. Can be manage but I need another option. Thanks
You seem to be working with a Date Structure, which as VBS says - hard to represent as numbers only. Use the CDate to get a date object from the string (If needed change the representation of that string to (YYYY-mm-dd ...). With the DateAdd method you can add days, years etc; and finally the FormatDateTime will create an output of your wish.

Get Windows Long Time Format

I'm trying to get the long time format in Windows (like "hh:mm:ss tt"). I can get the short time format like this:
GetLocaleInfoEx(NULL, LOCALE_STIMEFORMAT, format, 100);
I can't seem to find a constant for LOCALE_LTIMEFORMAT or anything like that. I can get the short time, short date and long date, but how can I query the current user's long time format?
As far as I can tell, windows defines the 'long' time format by LOCALE_STIMEFORMAT (set to something like "hh:mm:ss"), and the short time as LOCALE_SSHORTTIME (which, according to MSDN, is valid for Windows 7 and later).
Does that correspond to your findings, i.e. does it match the user preference in the Region and Language Control Panel item?
For the t specifier, if it is not included into the locale format, then either you are left with always using a custom format (like gbjbaanb said), or perhaps examining the format string for the presence of t or tt, and if absent adding it yourself (though, this might lead to odd results for cultures expecting the tt before the general time, for instance). This should not be necessary though, as the time format used by the locale is responsible for yielding time-strings that make sense (distinguishing between AM and PM, for instance).
What you are looking for is already included in LOCALE_STIMEFORMAT. Sample code:
wchar_t format[80]; // 80 is always enough
int ret = GetLocaleInfoEx(
LOCALE_NAME_USER_DEFAULT,
LOCALE_STIMEFORMAT,
format,
sizeof(format) / sizeof(*format));
if (ret == 0) die(GetLastError());
std::wcout << format << std::endl;
Output on my machine (I live in the USA):
h:mm:ss tt
The "tt" part will be absent for any culture or locale customization that does not display the AM/PM designator.
The LOCALE_STIMEFORMAT is the long time format. To get the short time format you can use LOCALE_SSHORTTIME starting with Windows 7 or cut off the seconds.
To confirm this simply change the long time format in your Control Panel / Region and Language settings.
Try using it with the LOCALE_S1159 and LOCALE_2359 constants which return the text for the AM/PM designators.
I think the issue is that time format is a time format, down to the second. You have to format it yourself if you want AM/PM just like you do with daylight savings time or timezone indicators.

Changing the timezone strings of date_lang.php

CodeIgniter stores timezones for its date class in
system/language/english/date_lang.php
I would like to change the strings in this file so that
$lang['UM12'] = '(UTC -12:00) Baker/Howland Island';
$lang['UM11'] = '(UTC -11:00) Samoa Time Zone, Niue';
would instead be
$lang['-12:00'] = '(UTC -12:00) Baker/Howland Island';
$lang['-11:00'] = '(UTC -11:00) Samoa Time Zone, Niue';
Is this possible at all?
Any change I make to the UM__ portion of one line makes it show as a blank on the dropdown. The remaining (unchanged) lines appear OK.
I have also tried to clone this file to application/language/english/ with similar bad results.
Any insights on this?
It looks like this would require hacks to the date_helper.php file which I am not willing to do.
Instead, the date class in CI has the timezones() function which allows you to convert from, for example, UM5 to -5. In that case one can wrap this function around the U__ value coming from the view/dropdown -- and then save it to DB as -5 or some other INT.
Since I want to show the user their selected timezone on that same dropdown, I am forced to have DB fields for the U__ and INT timezone formats. As far as I know, there is no CI function to convert from -5 to UM5.
So, for the user, I pull the U__ format into the view to autopopulate the dropdown.
For timezone conversions and such, I use the INT format.

Resources