How to display date in date field with SAP B1 SDK? - sapb1

I know how to display value in field of matrix in SAP B1 SDK, but I don't know how to display date in date field.
The variable FromDate contains a date from database and I want to display it in date field.
Below VBS code failed:
mtx2.Columns.Item("C_1_5").Cells.Item(mtx2.RowCount).Specific.string = FromDate
Below VBS code displays nothing in the field:
mtx2.Columns.Item("C_1_5").Cells.Item(mtx2.RowCount).Specific.string _
= Format(FromDate, "dd/MM/yyyy")
Does anyone know how to set the value of a date field?

I did it. I converted variable instead of field of query
Thank you

Related

MS Access form date range of single date yields no results

The form uses begin date and end date text boxes formatted as "General Date" to filter results. They are generally filled using the calendar date picker tool as format m/d/yyyy. ODBC SQL table that it's pulling the date field from is also showing format "General Date" in Design View but the field includes date and time as format m/d/yyyy H:MM:SS AM/PM.
When the same date is entered in the form begin and end date it shows no results, but I am told by my team in the past it has shown results. I am assuming that this is due to the form date picker including no time and defaulting to 12 AM in both boxes when the query runs. If that is/may be the case, is there a way to edit the end date text box to default to 11:59:59 PM of the date selected?
10/28 EDIT: I was asked to provide the SQL that refers to the end date text box. For context: the command button on the form opens query dbo_GEN_INSP_Count_Daily which is based on query dbo_GEN_INSP_Count_Monthly where the text box is mentioned. See below.
query dbo_GEN_INSP_Count_Daily
SELECT DateValue([INSP_DTE]) AS Insp_Date, Count([INSP_DTE]) AS DailyCount
FROM dbo_GEN_INSP_Count_Monthly
GROUP BY DateValue([INSP_DTE]);
query dbo_GEN_INSP_Count_Monthly
SELECT dbo_VEHICLE.DMV_VIN_NUM, dbo_INSPECTION_GENERAL.INSP_DTE, dbo_INSPECTION_GENERAL.CI_NUM, dbo_INSPECTION_GENERAL.DMV_FACILITY_NUM, dbo_INSPECTION_GENERAL.VIP_UNIT_NUM
FROM dbo_INSPECTION_GENERAL INNER JOIN dbo_VEHICLE ON (dbo_INSPECTION_GENERAL.VIP_UNIT_NUM = dbo_VEHICLE.VIP_UNIT_NUM) AND (dbo_INSPECTION_GENERAL.DMV_FACILITY_NUM = dbo_VEHICLE.DMV_FACILITY_NUM) AND (dbo_INSPECTION_GENERAL.CI_NUM = dbo_VEHICLE.CI_NUM) AND (dbo_INSPECTION_GENERAL.INSP_DTE = dbo_VEHICLE.INSP_DTE)
WHERE (((dbo_INSPECTION_GENERAL.INSP_DTE) Between [Forms]![Form1]![StartDate] And [Forms]![Form1]![EndDate]));
I'm not sure how it would play with your ODBC connection, but in the date field in the form under the data tab in the property sheet there is a default value for the form, just like in the MS Access table. You could try to put your default time in there at 11:59:59, it will automatically put quotes around it and it should reflect in your form.
You could also create a default constraint on the database itself to reflect 11:59:59 for the end date if nothing is there. Going this route you would probably need to break up your time and date fields in the database and bring them together in MS Access with a function. That way if a date was placed there with no time it would default to 11:59:59.
When the user enters the same date for both StartDate and EndDate, you want the query to return all rows containing that date regardless of the time component stored with the date.
So, instead of your current Between ... And approach, make the endpoint target less than one day after EndDate.
WHERE
dbo_INSPECTION_GENERAL.INSP_DTE >= Forms!Form1!StartDate
And dbo_INSPECTION_GENERAL.INSP_DTE < (DateValue(Forms!Form1!EndDate) + 1)

VBA date format code

I was wondering if there is any possibility to write a VBA code where the column A should always have a date format like this: 12.10.2017 (not 12/10/2017 or 12-10-2017). If anything else is written in the column A like "12" or "car" the entry should be deleted. It has to accept only the date format mentioned above.
I used data validation for this, with length 10 and the date format to take only "." into consideration, but I want to do it as a VBA code instead.
Thanks!
A valid date is a long representing the number of days since the 1st january 1900. So a valid date would be 45603. You can display this date in any format you wish using the format codes d, m and y . So to display the date as dd.mm.yyyy then set that numberformat in the cells in column A. Your problem though is that Excel will only accept a date entered as either a long or in a built in date format (using /, - or space as a separator). You could allow the users to enter a text string in the format dd.mm.yyyy and then convert that string into a date and then reject it if the conversion didn't result in a valid date - but wouldn't it be easier to just train your users to enter dates correctly?

how to assign User defined date in vba excel

I need to assign a date for the user to give manual date as input and make use of input at later stage. when the user inserted manual date , it has to be used for the naming conventions for the file name. Ex football 20160601.xlsx
I have gone through some website but could not able to find any answers as per my requirement.
My code:
Sub date()
date_test = Now()
Range("A1") = Format(date_test, "mm.dd.yy") ' how to aassign this date as a user defined date( as manual date) something like msg box but not msgbox.
End date
Dim inputDate as Date
Date = Format(InputBox("Enter a Date", "Input"),"yyyy-mm-dd")
Something like this?
If you want a Datepicker to select the desired date, then create a new userform and add the "Microsoft Date and Time Picker Control" (Tools->Additional Controls) to the Form. Then you can use it's value like this: Format(DatePicker1.Value,"yyyymmdd")

Sharepoint 2010 dates and calculated fields

For reasons I don't pretend to understand calculated fields that are set to return a date return the value in code in this format:
"datetime;#2015-04-25 00:00:00"
so dim myDate as datetime = oMasterItem("Contract End Date") fails, and you can't cast the value either.
How do I convert that to a real date format without doing string manipulation ?
(or am I missing something obvious?)
Many thanks!
Check this out:
SharePoint - get value of calculated field without manual parsing
You can do it by:
SPFieldCalculated cf = (SPFieldCalculated)myItem.Fields["CIDandTitle"];
string value = cf.GetFieldValueForEdit(myItem["CIDandTitle"]);
or
string value = cf.GetFieldValueAsText(myItem["CIDandTitle"]);

convert date in excel from dd-mm-yyyy to dd/mm/yyyy format and to check whether a date is valid or not

I'm having a hard time in converting the date from dd-mm-yyyy format to dd/mm/yyyy format.
For Example,
When i enter a date in excel as 25/02/2012 (dd/mm/yyyy), after entering the date if go in the next line it converts the date in the 25-02-2012 (dd-mm-yyyy) format.
what i want to do is that when i enter the date in (dd/mm/yyyy) format in excel it should keep it as it is and should not change it back to (dd-mm-yyyy) format when i go the next cell.
when i enter my date as the current system date my code gives me an error, i am having trouble validating the date i.e. is the date entered is a valid date or not
Sub valid_date()
' ---------------------------------------------------------------------
' Final Code - Trial
' ---------------------------------------------------------------------
Dim d1 As Variant
Dim IssueDate As Variant
Dim str As Variant
d1 = Worksheets("Sheet1").Cells(6, 1).value
MsgBox " The Issue Date format is " & d1
sysdate = Date
MsgBox "System Date is " & sysdate
If IsDateValid(d1) Then ' if date is in dd/mm/yyyy format then print this
If (d1 > sysdate) Then
MsgBox "Invalid date"
End If
End If
End Sub
Function IsDateValid(pdate) As Boolean
IsDateValid = False
Set RegExp = CreateObject("VBScript.RegExp")
' it only matches whether date is in dd/mm/yyyy format or not
'
' [1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1] ---> it allows the DATE from 01 to 31
' [1-9]|0[1-9]|1[0-2] ---> it allows the MONTH from 01 to 12
' 1[9][0-9][0-9]|2[0][0-9][0-9] ---> it allows the YEAR from 1900 to 2099
'
' below is the regular expression for checking the date in dd/mm/yyyy format
RegExp.Pattern = "^([1-9]|0[1-9]|1[0-9]|2[0-9]|3[0-1])[/]([1-9]|0[1-9]|1[0-2])[/](1[9][0-9][0-9]|2[0][0-9][0-9])$"
' check whether the date is in dd/mm/yyyy format or not....
tempdate = RegExp.Test(pdate)
If tempdate Then ' if tempdate is in dd/mm/yyyy format than proceed further
'If isdate(tempdate) Then ' if date is a valid date then proceed further
If isdate(pdate) Then
IsDateValid = True
Else
IsDateValid = False
End If
Else
IsDateValid = False
End If
End Function
i'm using the above mentioned code by using a regular expression to check whether the date is in dd/mm/yyyy format or not
but the problem which i'm facing is that it takes the date in excel as dd-mm-yyyy format whenever i enter the date in dd/mm/yyyy format.
i have updated my code a bit,
i also need one more help when i enter my date as the current system date it gives me error
for example,
when i enter my date as 09/09/2012 (suppose this your current system date) and when i check this date using IsDate method, it gives me an error
i have again edited my code,
Can anyone please help me on this
You don't need VBA/RegEx. Select the cells/columns where you input dates and create a Custom number format: dd/mm/yyyy. Now no matter how you type in a valid date (05-05-2000, 3-1-2010, 14/6-1990, etc.), it should be formatted as dd/mm/yyyy.
And, as Olle points out, you should use the Date object rather than Variant if you are going to be manipulating dates in VBA. This way you're working with the serial number and not a string with potential formatting issues.
First, I suggest you check the regional settings for dates on your computer. If you set it to use the "dd/mm/yyyy" format it will be used by Excel as well and hopefully remove the need for any RegEx VBA-code.
Second, if you do need to use VBA to reformat dates, I strongly suggest you use the Date data type instead of Variants. I also advise you to use Option Explicit at the top of your code and explicitly declare any variables in order to minimize typos and produce better quality code.
Third, I've looked through your code some more and it seems it will never work:
1. Because it is never declared, tempdate is a Variant
2. You assign tempdate to be a boolean, from the result of RegExp.Test(pdate)
3. So when you check IsDate(tempdate) it will always be false, since a boolean can never be a Date.
Again, if you use the Date data type, you can skip the RegEx... :)
I use Adobe online PDF to Excel and dates display correctly as MM/DD/YYYY but when extracting month (=Month()) it returns the DD portion. It is being interpreted as DD/MM/YYYY. I saved the file as a .csv closed and restarted excel and opened the .csv file and the dates were correct MM/DD/YYYY.