How to print current Time and Date in Q Basic? - date

What is the command for displaying the time and date in qbasic? Could the syntax for the commands be given as well? And an explanation if possible?

You can use DATE$ and TIME$
These can also set the date and time as well.

The command for printing the time(current system time) is time$
The time$ is actually a function, in this case, no parameter is needed.
And the code is...
PRINT TIME$
The time is printed in hh: mm: ss format(hour: minutes: seconds).
And therefore the output would be something like this:
14:55:28
For printing the current system date, we use date$ function which is also a string function
The code is:
PRINT DATE$
The date is printed in mm-dd-yyyy format or month-day-year(American date format).
Hence the output will be:
02-17-2018
Hope it helps...

The QB date/time functions are:
DATE$ returns the date in a string in the form MM-DD-YYYY
TIME$ returns the time in a string in the form HH:MM:SS
When used as a command the date$ and time$ can be assigned to set the system date and time, for example DATE$ = "12-10-1990" or TIME$ = "12:10:10"
If the year is a leap year then the 29th day of February could be set. Otherwise if it is not a leap year then a syntax error will occur trying to set the date in February to the 29th.

Related

Date Increment Using Autohotkey

I'm looking for a way to set an arbitrary date, and every time I press a key it will print the day after it (tomorrow).
global jDate = "June 1, 1986"
^+z::
;Output our date in LongDate format
FormatTime, TimeString, %jDate%, LongDate
SendInput, %TimeString%
;Increment the date by a single day
jDate += 1, Days
Return
Unfortunately, it the code keeps starting jDate as today's current date/time rather than the past date I specify in the initial variable assignment. Not sure why. The incrementing works fine, it just increments starting from todays date rather that the 1986 date.
FormatTime is expecting any date/time input to be in the "YYYYMMDD..." format. Since what you've assigned to jDate doesn't fit that criterion, it assumes it's invalid and uses today's date. To make it work how you expect, just modify your jDate input.
jDate := "19860601" ; 1986 -> YYYY, 06 -> MM, 01 ->DD
A couple of things to note: (1) global is not needed in this context; (2) I would recommend getting out of the habit of assigning variables using the = comparator (use := assignment operator instead). It only works for legacy reasons but generates more confusion than it's worth. In the context that you're using it, the quotes would need to be removed.

Transform string monthly dates in Stata

I have a problem in Stata with the format of the dates. I believe it is a very simple question but I can't see how to fix it.
I have a csv file (file.csv) that looks like
v1 v2
01/01/2000 1.1
01/02/2000 1.2
01/03/2000 1.3
...
01/12/2000 1.12
01/02/2001 1.1
...
01/12/2001 1.12
The form of v1 is dd/mm/yyyy.
I import the file in Stata using import delimited ...file.csv
v1 is a string variable, v2 is a float.
I want to transform v1 in a monthly date that Stata can read.
My attempts:
1)
gen Time = date(v1, "DMY")
format Time %tm
which gives me
Time
3177m7
3180m2
3182m7
...
that looks wrong.
2) In alternative
gen v1_1=v1
replace v1_1 = substr(v1_1,4,length(v1_1))
gen Time_1 = date(v1_1, "MY")
format Time_1 %tm
which gives exactly the same result.
And if I type
tsset Time, format(%tm)
it tells me that there are gaps but there are no gaps in the data.
Could you help me to understand what I'm doing wrong?
Stata has wonderful documentation on dates and times, which you should read from beginning to end if you plan on using time-related variables. Reading this documentation will not only solve your current problem, but will potentially prevent costly errors in the future. The section related to your question is titled "SIF-to-SIF conversion." SIF means "Stata internal form."
To explain your current issue:
Stata stores dates as numbers; you interpret them as "dates" when you assign a format. Consider the following:
set obs 1
gen dt = date("01/01/2003", "DMY")
list dt
// 15706
So that date is assigned the value 15706. Let's format it to look like a day:
format dt %td
list
// 01jan2003
Now let's format it to be a month:
format dt %tm
list
// 3268m11
Notice that dt is just a number that you can format and use like a day or month. To get a "month number" from a "day number", do the following:
gen mt = mofd(dt) // mofd = month of day
format mt %tm
list
// dt mt
// 3268m11 2003m1
The variable mt now equals 516. January 2003 is 516 months from January 1960. Stata's "epoch time" is January 1, 1960 00:00:00.000. Date variables are stored as days since the epoch time, and datetime variables are stored as miliseconds since the epoch time. A month variable can be stored as months since the epoch time (that's how the %tm formatting determines which month to show).

PigLatin-Finding MonthEnd date for a given date

In Pig Latin, is there a built-in function to find the Month End date for a given date ? For example, if the given date is '2015-03-15', the month end date returned should be '2015-03-31' and if given date is '2015-04-15', the month end date should be '2015-04-30'.
This is how you do it:
REGISTER /usr/lib/pig/piggybank.jar;
DEFINE ISOToMonth org.apache.pig.piggybank.evaluation.datetime.truncate.ISOToMonth();
%declare END_OF_MONTH SubtractDuration(AddDuration(ToDate(ISOToMonth('2015-03-15')),'P1M'),'P1D')
A = LOAD 'DummyFileWithOneRow.txt' USING PigStorage(',') AS (f1:chararray, f2:chararray);
result = FOREACH A GENERATE
f1 AS f1,
$END_OF_MONTH AS end_of_month;
DUMP result
The result of this run is:
(1,2015-03-31T00:00:00.000Z).
You can now convert this result to your desired format.
You can do this calculation as part of the foreach on the loaded values.
The ordinary way to do such things, if you do not find that the language in question already has a built-in set of functions to "do such things," is to ... in this case:
Determine the first day of the current month. ("Month/01/Year" This is the only step that you "do by hand.")
Add "one month" to that. (There should be some kind of "DateAdd()" function in your language...)
Finally, using the same function, "subtract one day."
December 15th => December 1st => January 1st (of next year) => December 31st (of this year).
But first, look carefully. "Accountants want to do this sort of thing all the time." There is usually a pretty-good, sometimes very-good, set of functions to do date-manipulation. (And if they're not built-in to the language, there's often a contributed library of "goodies" that someone else already wrote and perfected.)

SAS date conversion from text.

Hi I have a date conversion problem in SAS,
I imported an excel file which has the following dates.,
2012-01-09
2011-01-31
2010-06-28
2005-06-10
2012-09-19
2012-09-19
2007-06-12
2012-09-20
2004-11-01
2007-03-27
2008-06-23
2006-04-20
2012-09-20
2010-07-14
after I imported the dates have changed like this
40917
40574
40357
38513
41171
41171
39245
41172
38292
39168
39622
38827
41172
40373
I have used the input function to convert the dates but it gives a strange result.,
the code I used.,
want_date=input(have_date, anydtdte12.);
informat want_date date9.; format have_date date9.;run;
I get very stange and out of the World dates., any idea how can I convert these?
You can encourage SAS to convert the data as date during the import, although this isn't necessarily a panacea.
proc import file=whatever out=whatever dbms=excel replace;
dbdsopts=(dbSasType=( datevar=date ) );
run;
where datevar is your date column name. This tells SAS to expect this to be a date and to try to convert it.
See So Your Data Are in Excel for more information, or the documentation.
From : http://www2.sas.com/proceedings/sugi29/068-29.pdf
Times are counted internally in SAS as seconds since midnight and
date/time combinations are calculated as the number of seconds since
midnight 1 January 1960.
Excel also uses simple numerical values for dates and times
internally. For the date values the difference with the SAS date is
only the anchor point. Excel uses 1 January 1900 as day one.
So add a constant.
EXAMPLES:
SAS_date = Excel_date - 21916;
SAS_time = Excel_time * 86400;
SAS_date_time = (Excel_date_time - 21916) * 86400;
As Justin wrote you need to correct for the different zero date (SAS vs. Excel).
Then you just need to apply a format (if you want to get a date variable to do calculations):
want_date = have_date-21916;
format want_date date9.;
Or convert it to a string:
want_date = put(have_date-21916, date9.);
In either case you can choose the date format you prefer.

How do I parse "YYYY-MM-DD" with joda time

I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD. I have test code like this:
DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD");
DateTime dateTime = dateDecoder.parseDateTime("2005-07-30");
System.out.println(dateTime);
Which outputs:
2005-01-30T00:00:00.000Z
As you can see, the DateTime object produced is 30 Jan 2005, instead of 30 July 2005.
Appreciate any help. I just assumed this would work because it's one of the date formats listed here.
The confusion is with what the ISO format actually is. YYYY-MM-DD is not the ISO format, the actual resulting date is.
So 2005-07-30 is in ISO-8601 format, and the spec uses YYYY-MM-DD to describe the format. There is no connection between the use of YYYY-MM-DD as a pattern in the spec and any piece of code. The only constraint the spec places is that the result consists of a 4 digit year folowed by a dash followed by a 2 digit month followed by a dash followed by a two digit day-of-month.
As such, the spec could have used $year4-$month2-$day2, which would equally well define the output format.
You will need to search and replace any input pattern to convert "Y" to "y" and "D" to "d".
I've also added some enhanced documentation of formatting.
You're answer is in the docs: http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormat.html
The string format should be something like: "yyyy-MM-dd".
The date format described in the w3 document and JodaTime's DateTimeFormat are different.
More specifically, in DateTimeFormat, the pattern DD is for Day in year, so the value for DD of 30 is the 30th day in the year, ie. January 30th. As the formatter is reading your date String, it sets the month to 07. When it reads the day of year, it will overwrite that with 01 for January.
You need to use the pattern strings expected by DateTimeFormat, not the ones expected by the w3 dat and time formats. In this case, that would be
DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("yyyy-MM-dd");