In my idl I have tried-
enum ButtonClicks { Monday, Tuesday, Wednesday, Thursday, Friday } ;
typedef enum ButtonClicks { Monday, Tuesday, Wednesday, Thursday, Friday};
I receive -
MIDL2025 [msg]syntax error [context]: expecting an identifier near ";"
MIDL2025 [msg]syntax error [context]: expecting the keyword "interface" or...
The problem is that the enum is contained within the RuntimeClass. Moving it outside of the RuntimeClass compiles OK
enum ButtonClicks { Monday, Tuesday, Wednesday, Thursday, Friday};
typedef enum { Monday, Tuesday, Wednesday, Thursday, Friday} ButtonClicks;
the top one should just work by itself, if you want to do it via typedef try the bottom one
Related
I need to create a column for a day of the week where values will be Monday, Tuesday, Wednesday...
and then apply a filter only for Friday.
The code I'm using is the following:
df = (
spark.table(f'nn_squad7_{country}.fact_table')
.filter(f.col('date_key').between(start,end))
.filter(f.col('is_client_plus')==1)
.filter(f.col('source')=='tickets')
.filter(f.col('subtype')=='trx')
.filter(f.col('is_trx_ok') == 1)
.withColumn('week', f.date_format(f.date_sub(f.col('date_key'), 1), 'YYYY-ww'))
.withColumn('month', f.date_format(f.date_sub(f.col('date_key'), 1), 'M'))
.withColumn('HP_client', f.col('customer_id').isNotNull())
.withColumn('local_time',f.from_utc_timestamp(f.col('trx_begin_date_time'),'Europe/Brussels'))
.withColumn('Hour', f.hour(f.col('local_time')))
.withColumn('Day', f.day(f.col('local_time')))
.filter(f.col('Hour').between(4, 8))
)
Here is the error I get:
AttributeError: module 'pyspark.sql.functions' has no attribute 'day'
How can I create a column for on a dayli basis? Thanks
You can use F.dayofweek, which returns an integer (1 = Sunday, 2 = Monday, ..., 7 = Saturday).
Alternatively, you can use F.date_format('local_time', 'E'), which returns a string like 'Sun', 'Mon', etc.
'EEEE' returns the string in full, e.g. Sunday, etc.
report out of account system comes out with month like "FEB 2017". I need to convert that string to a date that is the end of the month like 02/28/2017. Any ideas?
SELECT LastDayInMonth(DateValue(Mid("Feb 2017", 1, 3) & " 1, " &
Mid("Feb 2017", 5, 4))) AS LastDayInMonth
FROM yourTable
Explanation:
The concatenated term inside the call to DateValue() will be Feb 1, 2017, and will evaluate to the same date, at least for the sample data I used. In general, it will be the first day of the month for the data you showed us. Then, we use LastDayInMonth() to shift that date to the last day of the same month.
You can also use native functions, adding one month, subtracting one day:
MonthYear = "FEB 2017"
Ultimo = DateAdd("d", -1, DateAdd("m", 1, CDate("1 " & MonthYear)))
Ultimo -> 2017-02-28
How do I convert a text format e.g.
Thursday, 1 January 2009
to a date in sql?
Thank you
For SQL Server you can use:
SELECT CAST(
SUBSTRING('Thursday, 1 January 2009',
CHARINDEX(',', 'Thursday, 1 January 2009')+1, LEN('Thursday, 1 January 2009'))
AS DATETIME)
What type of text do you mean?
if you mean any type of text .... that isn't exist
if you mean text like '19900101' or like '1/1/2005' ... this will be converted to date automatic in sql server
I was wondering if there was a way to directly convert the integer DayOfWeek returns into a string representing the day like Monday, Tuesday etc.
Sample code:
MessageBox.Show(Date.Today.DayOfWeek)
This will return 6 (as of today). Is there a way to directly convert this into Saturday, for example? I don't really care what it really converts it into, but I want to do away with my Select Case:
Select Case Date.Today.DayOfWeek
Case 0
day = "Sunday"
Case 1
day = "Monday"
Case 2
day = "Tuesday"
Case 3
day = "Wednesday"
Case 4
day = "Thursday"
Case 5
day = "Friday"
Case 6
day = "Saturday"
Case Else
day = "Apocalypse: we're all boned."
End Select
Thanks :)
DateTimeFormatInfo.CurrentInfo.GetDayName.
A simpler way:
Dim day As String = Date.Today.DayOfWeek.ToString()
There's a DateTime format for that: dddd
Dim date1 As Date = #08/29/2008 7:27:15PM#
date1.ToString("dddd", CultureInfo.CreateSpecificCulture("en-US"))
With the CultureInfo you can get it in a specific language (it's optional)
For more info:
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx#ddddSpecifier
DateTime.DayOfWeek doesn't return an integer - it returns an enum of type DayOfWeek. I'd expect that to be converted into the name automatically, but maybe this is a VB subtlety; maybe something to do with using Date instead of DateTime? Try this:
MessageBox.Show(DateTime.Today.DayOfWeek.ToString())
This won't be culture-sensitive though - it will always just display the name of enum value, in English. If that's not good for you, use Zyphrax or itowlson's solution.
Date.Today.DayOfWeek.ToString will give you what you're looking for. Nice and easy.
Just in case others looked at this example. I believe it should be Case 0 for Sunday.
Case 0
day = "Sunday"
Ok, so I need to find the date of Monday this week programmatically.
For example, for this week Monday was on the 9th, so the date I need is: 09/11/2009
And when we roll over to next week it needs to calculate: 16/11/2009
I have tried doing this myself but I can't see how to do the arithmetic, thank you.
C#:
date.AddDays(1 - (date.DayOfWeek == DayOfWeek.Sunday ? 7 : (int)date.DayOfWeek));
VB.NET:
date.AddDays(1 - IIf((date.DayOfWeek = DayOfWeek.Sunday), 7, date.DayOfWeek))
Dim thisMonday As Date = Now.AddDays((Now.DayOfWeek - 1) * -1).Date
If today is a Sunday it gives the following Monday otherwise, gives the Monday this week.
Return givenDate.AddDays(1 - CType(IIf((givenDate.DayOfWeek = DayOfWeek.Sunday), 7, givenDate.DayOfWeek), Double))
If givenDate is a Sunday, counts back to the preceding Monday. Includes a CType to cast the IIf result to a Double to work with Option Strict On.