在vb.net中格式化日期值仍然返回错误的值 [英] Formatting Date value in vb.net still returning the wrong value
问题描述
Dim dateTo As Date
dateTo = dtpCRTo.Value.ToShortDateString
dateTo = Format(dateTo, dd / MM / yyyy)
如果cmbCRSupplier.Value =Then
selectionFormula ={Sales_Headers.Stage} ='6'AND {Sales_Lines.PaymentDate} <=# &安培; dateTo& #
我得到的问题是我测试的数据有一个 Sales_Headers.Stage
值为6,这很好,并且30/11/2016( Sales_Lines.PaymentDate
在英国, dd / MM / yyyy
)格式,即使我使用的 DateTimePicker
显示为11 2016年12月, dateTo
的价值为12/11/2016,即 MM / dd / yyyy
格式,所以报告显示没有数据,因为该日期是在付款日期之前。
为什么日期以这种格式返回,即使我格式化? / b>
编辑
另外,在将格式化部分放入之前, code> dtpCRTo.Value.ToShortDateString ,它仍然做同样的事情。
对于任何日期部分小于13,将该部分视为一个月,但一天中的部分为13或更多时,则可以正常工作。
编辑2:
我现在的查询如下:
Dim dateTo As Date = dtpCRTo.Value.AddDays(1).Date
dateTo =格式(dateTo,dd / MM / yyyy)
If cmbCRSupplier.Value =Then
selectionFormula ={Sales_Headers.Stage} ='6'AND {Sales_Lines.PaymentDate}< #& dateTo&#
这适用于所有日期,除了选择最后如果我选择1月31日,那么 dateTo
值将变为02/01/2017(2月2日),在公式中将其视为1月2日。
格式属性:
<$ pre>
1。DatePicker>属性> CustomFormat>(输入您想要的格式)
2.属性>格式>自定义
$ c $ Dim dateFormat As
$ b String
dt.Format = DateTimePickerFormat.Custom
dt.CustomFormat =dd / MM / yyyy
dateFormat = dt.Text
它可以是你想要的属性或代码隐藏的格式。
The code below is the code I'm using to set the selection formula for my Crystal Report.
Dim dateTo As Date
dateTo = dtpCRTo.Value.ToShortDateString
dateTo = Format(dateTo, "dd/MM/yyyy")
If cmbCRSupplier.Value = "" Then
selectionFormula = "{Sales_Headers.Stage} = '6' AND {Sales_Lines.PaymentDate} <= #" & dateTo & "#"
The issue I'm getting, is the data that I'm testing with has a Sales_Headers.Stage
value of 6, which is fine, and a Sales_Lines.PaymentDate
value of 30/11/2016 (In UK, dd/MM/yyyy
) format, however, even though the DateTimePicker
I'm using is showing 11th December 2016, the value of dateTo
is returning as 12/11/2016, which is MM/dd/yyyy
format, so the report shows no data, as that date is before the payment date.
Why is the date returning in this format, even though I'm formatting it?
EDIT
Also, before I put the formatting section in, and had dtpCRTo.Value.ToShortDateString
in the selection formula, it still did the same thing.
For any dates where the day part is less than 13, it treats that part as a month, but works fine once the day part is 13 or more...
EDIT 2:
The query I have now is as follows:
Dim dateTo As Date = dtpCRTo.Value.AddDays(1).Date
dateTo = Format(dateTo, "dd/MM/yyyy")
If cmbCRSupplier.Value = "" Then
selectionFormula = "{Sales_Headers.Stage} = '6' AND {Sales_Lines.PaymentDate} < #" & dateTo & "#"
This works for all dates, except when choosing the last day of each month. If I'm selecting 31st January, the dateTo
value will become 02/01/2017 (2nd February), which is treated in the formula as 2nd January. Is there a way around this?
解决方案 Format Properties:
1. DatePicker > Properties > CustomFormat > (Enter format you want here)
2. Properties > Format > Custom
Code Behind:
Dim dateFormat As String
dt.Format = DateTimePickerFormat.Custom
dt.CustomFormat = "dd/MM/yyyy"
dateFormat = dt.Text
Its either you want to format in Properties or in Code Behind.
这篇关于在vb.net中格式化日期值仍然返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!