Get month from today

Hi,
I expect month in letter or number to filter by month and check Col 4th and Col 5th where the value is >0 get the value. In each of the column value will be >0.

Please help

Month Index Month Year Accrual Days Reversal days
3 March 2019 0 2
4 April 2019 3 0
5 May 2019 0 0
6 June 2019 0 2
7 July 2019 2 0
8 August 2019 0 1
9 September 2019 0 3
10 October 2019 1 0
11 November 2019 0 1
12 December 2019 0 4
1 January 2020 0 0

System.DateTime.Now().Month.ToString(“MMM”)

I’m getting output as MMM

Hi @Sanjoy_Kr_Singharoy,

If you want to convert March to 03.

Use the below expression

Datetime.parseexact(“March”,“MMMM”,system.globalisation.cultureinfo.invariatculture).tostring(“MM”)

First I want to fetch current month then from the DT get the Accrual or Reversal value as per the month

Try date.now.tostring(“MMMM”)

Thanks now I’m getting March
Also, could you please on the remaining part

Considering you have read the table data into a data table, use for each row to loop through the dt.

For each row, you can access the columns and have if condition as per your requirement to validate if its >0

If colum heading is fixed use like this inside for each row,

Item.row(“column_name”). ToString

I tried like
row.item(“Month”).tostring
getting all the month from April onwards
But I want March corresponding Accrual or Reversal value >0

Can you paste a screenshot?

This is what has to be done

For each row in datatable (item is the counter variable)

  if item.row("Month"). ToString = date.now.tostring(“MMMM”)
             If item.row("Accruel days") >0 
                          Do as per requirement with that value

used
row.Item(“Accrual Days”)>0
but error
Compiler error encountered processing expression “row.item(“Accrual Days”)>0”.
Option Strict On prohibits operands of type Object for operator ‘>’

Not able to upload image

Use Convert.ToInt32(row.Item(“Accrual Days”). ToString) >0

Thanks, the error disappeared now
but can I get the value by setting a variable to Convert.ToInt32(row.Item(“Accrual Days”).ToString

Yes. You can assign that value to a variable of type int and use as required.

Please mark as solution if the suggestions solved your issue.

Thanks,
Arun

Thank you. it worked.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.