Lua 24-hour format of an hour without leading zeros - date

I need to get the act hour in Lua without the leading zeros(in 24 hour mode)
it's like date("G") in PHP
I actually have this code
os.date("%d-%m-%Y %H")
but it returns me 01 , 02 , 03 .... and I need to get 1 , 2, 3 etc
I found this but it doesn't seem to help me to solve my problem
os.date formats

You can just remove the leading zero:
os.date("%d-%m-%Y %H"):gsub(" 0"," ")

Try to get hour :
local hour = os.date("%H")
And try to format with string.format :
string.format("%d", hour)

Related

Unix Timestamp 13 Digits : CFSET puts it to 15 : ColdFusion

UNIX Timestamp in Coldfusion becomes 15 digits
1st set and call: 1666807130469
2nd set and call: 166680713046918XYZKEY999YYY5000{"symbol":"ETHUSDT","orderQty":0.03,"side":"Sell","orderType":"MARKET"}
Changes it to 15. I think I need it restricted to 13. Easiest way. Probably something simple? Why would it change it?
<cfset unixdatetimeNow = dateConvert( "local2Utc", now() )>
#unixdatetimeNow.getTime()#
<cfset encode = '#unixdatetimeNow.getTime()#XYZKEY999YYY{"symbol":"ETHUSDT","orderQty":0.03,"side":"Sell","orderType":"MARKET"}'>

how to get a week's date with autohotkey

i'm using autohotkey to work with date, i need to catch the day a week ago
example
if today is the 28th then I have to take the 21st of last week
calendar
in the following script I take the current date
FormatTime, date, , dd/MM/yyyy
MsgBox %date%
I even thought of a logic, to take the current day subtract by 7 that will take the day a week ago. I need help to create a better script
28 - 7 = 21
if anyone can help me thanks :)
Just subtracting numbers would be bad when you encountered a change between months.
Would have to create custom logic for that.
Luckily AutoHotkey's += operator supports date/time math.
So this is all you need:
;we're starting off the date1 variable as blank,
;which means the current time will be used.
date1 += -7, days
FormatTime, finalDate, % date1, dd/MM/yyyy ;format the result to our desired format
MsgBox, % finalDate
I did it that way
FormatTime, date_, , dd
sub += date_-7
FormatTime date, , /MM/yyyy
MsgBox,%sub%%date%

How to convert particular string to date in Talend

In talend
Oct 21 - Oct 27 (2019)
is there any way to convert above text to date format, I only want 21 oct 2019 as 21/10/2019 format
Yes, it is not simple, as you have two dates on one field only, with Year appearing only once.
You can achieve this with tMap_1 --> tNormalize --> tMap_2
In tMap_1 you will have to separate "MMM-dd" from "YYYY", which appears at the end of your string. Use split method on your input field :
myFlow.myDateField.split("\\(")[0] will give you the part with `Oct 21 - Oct 27`
myFlow.myDateField.split("\\(")[1] will give you the part with the year.
Use StringHandling.LEFT to get the year only, without the closing parenthesis.
Use StringHandling.TRIM to get rid of extra spaces.
Then you will have two fields in the output.
You can then use tNormalize (normalize on "-") to put the year in front of every MMM/dd field.
In the output you'll have two rows and two columns :
"Oct 21|2019"
"Oct 27|2019"
In the final tMap , concatenate your two input fields as you wish, and use TalendDate.parseDateLocale to parse your date. (TalendDate.parseDate won't work as you have "Oct", which requires parseDateLocale method to work).

looking for spark scala(java) code for date string with spaces in between with specific conditions

need some suggestions on below requirement.
Each response help a lot thanks in advance....
I have a date of type String with timestamp ex: Jan 8 2019 4:44 AM
My requirement is if the date is single digit I want date to be 1 space and digit
(ex: 8) and if the date is 2 digits which is dates from 10 to 31 I want date with no space(ex:10) and also same for hour in timestamp.
to summarize: if the date is 1 to 9 and hour in timestamp is 1 to 9 looking for below string
Jan 8 2019 4:44 AM
if the date is 10 to 31 and hour in timestamp is 10 to 12 looking for below string
Jan 18 2019 12:44 AM
right now I am creating a date in following way:
val sdf = new SimpleDateFormat("MMM d yyyy h:mm a")
but the above format satisfies only one condition which is dates from 1 to 9.
my application is spark with scala so looking for some spark scala code or java.
I appreciate your help...
Thanks..
java.time
Use p as a pad modifier in the format pattern string. In Java syntax (sorry):
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(
"MMM ppd ppppu pph:mm a", Locale.ENGLISH);
System.out.println(LocalDateTime.of(2019, Month.JANUARY, 8, 4, 44)
.format(formatter));
System.out.println(LocalDateTime.of(2019, Month.JANUARY, 18, 0, 44)
.format(formatter));
Jan 8 2019 4:44 AM
Jan 18 2019 12:44 AM
And do yourself the favour: Forget everything about the SimpleDateFormat class. It is notoriously troublesome and fortunately long outdated. Use java.time, the modern Java date and time API.
Link: Oracle tutorial: Date Time explaining how to use java.time.
To quote the DateTimeFormatter class documentation:
Pad modifier: Modifies the pattern that immediately follows to be padded with spaces. The pad width is determined by the number of pattern letters. This is the same as calling DateTimeFormatterBuilder.padNext(int).
For example, 'ppH' outputs the hour-of-day padded on the left with spaces to a width of 2.

Generating Dates between two date ranges in AWK

I need to create a list of days between a date interval.
Say for example from 2001-01-01 to 2009-12-31:
2001-01-01
2001-01-02
2001-01-03
..
2009-12-29
2009-12-30
2009-12-31
I know how to do it but maybe someone has a script already made?
If not, I will make such a script and upload it so others won't waste time on this when they need it.
I do not know awk from GnuWin32, but if the functions "mktime" and "strftime" are available, you can try the following code:
BEGIN {
START_DATE="2001-02-01"
END_DATE="2001-03-05"
S2=START_DATE
gsub("-"," ",S2)
T=mktime(S2 " 01 00 00")
if (T<0)
printf("%s is invalid.\n",START_DATE) >> "/dev/stderr"
else
{
for(S=START_DATE; END_DATE>S ;T+=86440) print S=strftime("%F",T)
}
}
The key is to convert the start date to a number meaning the seconds since the Epoch, add 86400 seconds (one day or 24 x 60 x 60) and convert back to the ISO date format.
After some trials I realized the mktime() function admits wrong dates as good (for instance, 2000-14-03).
Best regards