[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Date calculations with c# in asp.net web forms

Posted on 2016-10-01
2
Medium Priority
?
38 Views
Last Modified: 2016-10-01
I'm using c# in a asp.net web forms page.

The fiscal year period runs from July 1 to June 30 of the next year.

For example FiscalYear 2017, is the period from 07/01/2016 to 06/30/2017

For example FiscalYear 2016, is the period from 07/01/2015 to 06/30/2016

On my page I'm going to have a asp Textbox and a asp button

What I want is, I'm going to type a date in the Textbox and then when I click the button , on the same page I want it to display a message saying what fiscal year that date is in.

So for example, if I type this date in the Textbox  08/23/2015 and then I press the button, the message on the page will say
"The date you entered is in FiscalYear 2016"

So for example, if I type this date in the Textbox  02/12/2014 and then I press the button, the message on the page will say
"The date you entered is in FiscalYear 2014"

Any ideas of what I do with the date entered in the Textbox in order to find what fiscal year it is in?
That's the part I'm having trouble with.
0
Comment
Question by:maqskywalker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 83

Accepted Solution

by:
David Johnson, CD, MVP earned 2000 total points
ID: 41825068
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ee_28973752
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
        string year;
        string output;
         string input = textBox1.Text;
            try
            {
                DateTime dt = Convert.ToDateTime(input);
                if ((dt.Month <= 6) && (dt.Day <= 30))
                {
                    year = (dt.Year - 1).ToString();
                }
                else
                {
                    year = dt.Year.ToString();
                }
                output = "The Date you Entered is in Fiscal Year " + year;
                label1.Text = output;
            }
            catch {
                label1.Text = "Invalid Date";
                    }
        }
    }
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 41825112
Thanks
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question