getdate和int值之间的差异? [英] diffrence between getdate and an int values?

查看:73
本文介绍了getdate和int值之间的差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我有一个日期和一个整数.我想从给定的日期中减去该整数.


hi friends,
i have a date and an int. i want to subtract that integer from a given date .


DateTime dt = new DateTime();
            dt = Calendar.SelectedDate;
            dt = dt.AddDays(Convert.ToInt32(txtadd.Text));
           lblgetdate.Text = dt.ToLongDateString();
            DateTime sDate = new DateTime();
            sDate = Calendar.SelectedDate;
            DateTime eDate = new DateTime();
            eDate = Convert.ToDateTime(lblgetdate.Text);
            DayOfWeek fWeek = DayOfWeek.Friday;

         
            int totCount = CountDayOcurrence(sDate, eDate, fWeek);
            lblweekday.Text = totCount.ToString();   


我想从lblweekday中减去lblgetdate.


i want to subtract lblgetdate from lblweekday.

推荐答案

您可以这样做.但是,您想从(例如)DateTime的哪个组成部分中减去此整数.年/日/秒,依此类推.

基本上,使用TimeSpan 类进行区别.
使用FromDays,FromHours方法或您需要进行区别的任何一种方法.
请参见此处 [
You can do that. However, which component of the DateTime do you want to subtract this integer from e.g. year / day / second and so on.

Basically, use the TimeSpan class to do the difference.
Use the FromDays, FromHours method or whichever one that you need to do the difference.
See here[^].


尝试此
Dim dt As New Date
dt = "26-12-2011"
Dim a As Integer = 6
Dim a1 As Integer = 1

 While a1 <= Len(dt)
   If a = Mid(dt, a1, 1) Then
      MsgBox(a)
      Exit While
   End If
   a1 = a1 + 1
 End While


这篇关于getdate和int值之间的差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆