Getting current month (full month name - August 04, 2016) format with Selenium IDE - selenium-ide

I have date format: August 04, 2016 how I can get this format to enter in the date field?

Check this out:
storeEval | monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; d = new Date(); result = monthNames[d.getMonth()]+' '+ d.getDate() +', ' + d.getFullYear(); result; | date
echo | ${date}

It depends on the language you use. For example in Java you can use the SimpleDateFormat utility with the following pattern:"MMM d,yyyy".

Related

Create date by components in swift

Hello i have a problem: I try to create date by components but it's give me wrong hours..
For example, I want to have 2022-04-24 00:00:00
Here the code
func createDate(year: Int, month: Int, day: Int, hour: Int, minutes: Int)->Date {
let calendar = Calendar.current
var dateComponents = DateComponents()
dateComponents.year = year
dateComponents.month = month
dateComponents.day = day
dateComponents.hour = hour
dateComponents.minute = minute
let date = calendar.date(from: dateComponents)!
return date
}
let date = createDate(year: 2022, month: 4, day: 24, hour: 0, minute: 0) // return 2022-04-23 22:00:00 +0000
let date2 = createDate(year: 2022, month: 4, day: 24, hour: 9, minute: 0) // return 2022-04-24 7:00:00 +0000
I have 2 hours late.
I'm in France, i set my virtual device in France region.
Do you know where is the error ?
Try adding "GMT" timezone, such as:
dateComponents.timeZone = TimeZone(identifier: "GMT")

Trouble with Date.ParseStrategy not recognizing month: .abbreviated

I am trying to convert a string date into a Date with the following code:
let myStrategy = Date.ParseStrategy(format: "\(month: .abbreviated) \(day: .twoDigits), \(year: .defaultDigits) at \(hour: .twoDigits(clock: .twelveHour, hourCycle: .zeroBased)):\(minute: .twoDigits) \(dayPeriod: .standard(.wide))", timeZone: .current)
let date1 = try? Date("Feb 21, 2022 at 10:00 AM", strategy: myStrategy)
print(date1)
print(type(of: date1))
let date2 = try? Date("2 21, 2022 at 10:00 AM", strategy: myStrategy)
print(date2)
print(type(of: date2))
And my output is
nil
Optional<Date>
Optional(2022-02-21 15:00:00 +0000)
Optional<Date>
If I am specifying month: .abbreviated1 … What does date1 NOT work and WHY does date2 work??
ALL of my data is coming in with 3 character months (e.g., Jan, Feb, Mar, etc.)
How Can I Make This Work Correctly?

Date calculations in power shell

I wrote a piece of code where I need 10 dates that are 110 hours apart but I am missing something. Can you please advise?
$Date = [DateTime] "10/17/2020 01:11 AM"
$Int = 10
Do { $Date.AddHours(110); $Int-- } While ($Int -ge 1)
Output:
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
Wednesday, October 21, 2020 3:11:00 PM
DateTime in .NET is implemented as an immutable type - its value cannot be modified once created.
So the Add() method returns a new DateTime object reflecting the time difference, but the existing object assign to $Date still has the same value.
You'll need to overwrite $Date with the new value on each iteration:
Do { $Date = $Date.AddHours(110); $Date; $Int-- } While ($Int -ge 1)

Get array of dates for hours, days, weeks, months between current date/time and end date/time

I want to create a range of Date objects using Swift 3 and was wondering if there is an API somewhere that simplifies what I want to do, for example:
One of the things I want to do is produce a range of Dates for the period of 1 year (January through December), each Date representing the 1st of every month.
I know I can do all this within a loop like so...
func monthsInYear() {
var calendar = Calendar.current
let date = Date()
let monthsOfYearRange = calendar.range(of: .month, in: .year, for: date)
print(monthsOfYearRange as Any)
if let monthsOfYearRange = monthsOfYearRange {
let year = calendar.component(.year, from: date)
for monthOfYear in (monthsOfYearRange.lowerBound..<monthsOfYearRange.upperBound) {
let components = DateComponents(year: year, month: monthOfYear)
guard let date = Calendar.current.date(from: components) else { continue }
print(date.description(with: Locale.current))
}
}
}
Which produces the following output...
Sunday, January 1, 2017 at 12:00:00 AM Eastern Standard Time
Wednesday, February 1, 2017 at 12:00:00 AM Eastern Standard Time
Wednesday, March 1, 2017 at 12:00:00 AM Eastern Standard Time
Saturday, April 1, 2017 at 12:00:00 AM Eastern Daylight Time
Monday, May 1, 2017 at 12:00:00 AM Eastern Daylight Time
Thursday, June 1, 2017 at 12:00:00 AM Eastern Daylight Time
Saturday, July 1, 2017 at 12:00:00 AM Eastern Daylight Time
Tuesday, August 1, 2017 at 12:00:00 AM Eastern Daylight Time
Friday, September 1, 2017 at 12:00:00 AM Eastern Daylight Time
Sunday, October 1, 2017 at 12:00:00 AM Eastern Daylight Time
Wednesday, November 1, 2017 at 12:00:00 AM Eastern Daylight Time
Friday, December 1, 2017 at 12:00:00 AM Eastern Standard Time
However, what I'm looking for is an easier more concise way to do this. I want to do the same for weeks in a given month, days within a given week, hours within a given day which I am able to do, but it uses the same loop.
This is what I went with - stuck with "the loop" :S
func monthsInYear() {
print()
print("monthsInYear")
var calendar = Calendar.current
let date = Date()
let monthsOfYearRange = calendar.range(of: .month, in: .year, for: date)
//print(monthsOfYearRange as Any)
if let monthsOfYearRange = monthsOfYearRange {
let year = calendar.component(.year, from: date)
for monthOfYear in (monthsOfYearRange.lowerBound..<monthsOfYearRange.upperBound) {
let components = DateComponents(year: year, month: monthOfYear)
guard let date = Calendar.current.date(from: components) else { continue }
print(date.description(with: Locale.current))
}
}
}
func weeksInMonths() {
print()
print("weeksInMonths")
var calendar = Calendar.current
let date = Date()
let weekOfYearRange = calendar.range(of: .weekOfYear, in: .month, for: date)
//print(weekOfYearRange as Any)
if let weekOfYearRange = weekOfYearRange {
let year = calendar.component(.year, from: date)
for weekOfYear in (weekOfYearRange.lowerBound..<weekOfYearRange.upperBound) {
let components = DateComponents(weekOfYear: weekOfYear, yearForWeekOfYear: year)
guard let date = Calendar.current.date(from: components) else { continue }
print(date.description(with: Locale.current))
}
}
}
func daysInWeek() {
print()
print("daysInWeek")
var calendar = Calendar.current
let date = Date()
let daysInWeekRange = calendar.range(of: .day, in: .weekOfMonth, for: date)
//print(daysInWeekRange as Any)
if let daysInWeekRange = daysInWeekRange {
let year = calendar.component(.year, from: date)
let month = calendar.component(.month, from: date)
let weekOfMonth = calendar.component(.weekOfMonth, from: date)
for dayOfWeek in (daysInWeekRange.lowerBound..<daysInWeekRange.upperBound) {
let components = DateComponents(month: month, day: dayOfWeek, weekOfMonth: weekOfMonth)
guard let date = Calendar.current.date(from: components) else { continue }
print(date.description(with: Locale.current))
}
}
}
func hoursInDay() {
print()
print("hoursInDay")
var calendar = Calendar.current
let date = Date()
let hoursInDayRange = calendar.range(of: .hour, in: .day, for: date)
//print(hoursInDayRange as Any)
if let hoursInDayRange = hoursInDayRange {
let year = calendar.component(.year, from: date)
let month = calendar.component(.month, from: date)
let weekOfMonth = calendar.component(.weekOfMonth, from: date)
let day = calendar.component(.day, from: date)
for hourOfDay in (hoursInDayRange.lowerBound..<hoursInDayRange.upperBound) {
let components = DateComponents(year: year, month: month, day: day, hour: hourOfDay, weekOfMonth: weekOfMonth)
guard let date = Calendar.current.date(from: components) else { continue }
print(date.description(with: Locale.current))
}
}
}
Which produces the following output when run:
monthsInYear
Sunday, January 1, 2017 at 12:00:00 AM Eastern Standard Time
Wednesday, February 1, 2017 at 12:00:00 AM Eastern Standard Time
Wednesday, March 1, 2017 at 12:00:00 AM Eastern Standard Time
Saturday, April 1, 2017 at 12:00:00 AM Eastern Daylight Time
Monday, May 1, 2017 at 12:00:00 AM Eastern Daylight Time
Thursday, June 1, 2017 at 12:00:00 AM Eastern Daylight Time
Saturday, July 1, 2017 at 12:00:00 AM Eastern Daylight Time
Tuesday, August 1, 2017 at 12:00:00 AM Eastern Daylight Time
Friday, September 1, 2017 at 12:00:00 AM Eastern Daylight Time
Sunday, October 1, 2017 at 12:00:00 AM Eastern Daylight Time
Wednesday, November 1, 2017 at 12:00:00 AM Eastern Daylight Time
Friday, December 1, 2017 at 12:00:00 AM Eastern Standard Time
weeksInMonths
Sunday, November 26, 2017 at 12:00:00 AM Eastern Standard Time
Sunday, December 3, 2017 at 12:00:00 AM Eastern Standard Time
Sunday, December 10, 2017 at 12:00:00 AM Eastern Standard Time
Sunday, December 17, 2017 at 12:00:00 AM Eastern Standard Time
Sunday, December 24, 2017 at 12:00:00 AM Eastern Standard Time
Sunday, December 31, 2017 at 12:00:00 AM Eastern Standard Time
daysInWeek
Monday, December 10, 1 at 12:00:00 AM GMT-04:56:02
Tuesday, December 11, 1 at 12:00:00 AM GMT-04:56:02
Wednesday, December 12, 1 at 12:00:00 AM GMT-04:56:02
Thursday, December 13, 1 at 12:00:00 AM GMT-04:56:02
Friday, December 14, 1 at 12:00:00 AM GMT-04:56:02
Saturday, December 15, 1 at 12:00:00 AM GMT-04:56:02
Sunday, December 16, 1 at 12:00:00 AM GMT-04:56:02
hoursInDay
Tuesday, December 12, 2017 at 12:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 1:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 2:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 3:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 4:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 5:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 6:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 7:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 8:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 9:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 10:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 11:00:00 AM Eastern Standard Time
Tuesday, December 12, 2017 at 12:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 1:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 2:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 3:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 4:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 5:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 6:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 7:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 8:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 9:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 10:00:00 PM Eastern Standard Time
Tuesday, December 12, 2017 at 11:00:00 PM Eastern Standard Time

Sorting in Spark SQL for the Month

I have a column as Month with Contents as
(Jan2016,Feb2016,Mar2016,Jun2016)
I'm trying to order it as
df.orderBy("Month")
But the month Col gets ordered as
Feb2016,Jan2016
in the alphabetical order, How can I order it by month?
I refer the code of Antot.
val monthWithIndex = Seq("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec").zipWithIndex.toMap
val monthSim = udf( (mon : String) => {
monthWithIndex( mon.substring( 0, 3))
})
val df = session.sparkContext.parallelize( Seq("Jan2016","Feb2016","Mar2016","Jun2016")).toDF("Month")
df.withColumn("newMonth", monthSim($"Month")).orderBy("newMonth").drop("newMonth").show
If you wanto order by year and month, you can add the year column by above code.
Parsing dates looks like a way to go:
import org.apache.spark.sql.functions.{to_date, month}
df.orderBy(month(to_date($"Month", "MMMyyy")))