Change System Custom Data - visual-studio

I use to program in VB6 and started the Visual Studio VB thing for past 6 months or so. I need to find a way to change the users PC system date format to custom format using VS2010
Without asking the user to go through the control panel
I had a look at the following code but it does not permantly set the system date format
Dim en As New CultureInfo("en-US")
Thread.CurrentThread.CurrentCulture = en
' Creates a DateTime for the local time.
Dim dt As New DateTime(2001, 7, 13, 4, 0, 0)
' Converts the local DateTime to the UTC time.
Dim utcdt As DateTime = dt.ToUniversalTime()
' Defines a custom string format to display the DateTime.
' zzz specifies the full time zone offset.
Dim format As [String] = "MM/dd/yyyy hh:mm:sszzz"
' Converts the local time to a string
' using the custom format string and display.
Dim str As [String] = dt.ToString(format)

Related

change year in date irrespective of date format using vbscript

I want to only change year in the date irrespective of date format. For example if date=05/20/2019 0r 05-20-2019 then it should change to 05/20/2017
Just use DateSerial() to replace the Year component.
Call SetLocale("en-us")
Dim oldDate: oldDate = CDate("05/20/2019")
Dim newDate: newDate = DateSerial(2015, Month(oldDate), Day(oldDate)

ADS retrieve whenchanged with AM or PM

I have a vbs file that queries the domain as below
queryTxt = "<"& domainname &">;" & _
"(&(objectclass=user)(objectcategory=person));"
queryTxt = queryTxt & "SAMAccountName,whenchanged"
But in some servers "whenchanged" is returning values as "8/18/2014 1:20:30 AM" and in some as "12-08-2014 04:54:58". I want to have the returning value as the first date format.
How to update the query so that I get a unique date format.
Queries to the whenChanged attribute return a Date value, so the display format is governed by the regional settings of the computer displaying the query results. Either change the date format in the computer's regional settings, or use a StringBuilder object for building a custom date format.

How do I convert Oracle internal date to Excel date in Excel?

I have a .csv file which was captured from an Oracle database. The date in the .csv file is in the Oracle internal format (not sure what it's called as I'm not familiar with Oracle). It looks like 16474
When I look at that date in the app we use to access the DB, the date is 2/6/2013.
However, when I import the .csv file into Excel and format the column as Short Date, it shows the date as 2/6/1945
I did a random sampling, and it looks like the month/day is always correct, but the year is off by 68 years. I'm assuming this is because Oracle's "beginning of time" is different than Excel's "beginning of time"
Any way to fix this so the dates show properly when importing the Oracle data into Excel?
I don't have access to anything on the Oracle side .. just the .csv file, and Excel. I'm also ultimately importing the Excel file into Access if that helps.
So far, I formatted the Oracle date as Short Date in Excel, and inserted a column next to my date column (J) and used the following:
=DATE(YEAR(J1)+68,MONTH(J1),DAY(J1))
I'm not sure if that is 100% accurate considering leap years
EDIT: I think this code may do it:
Public Sub ReplaceData()
Dim RangeCell As Range
For Each RangeCell In Selection
If IsNumeric(RangeCell.Value) Then
lngDate = CLng(RangeCell.Value)
RangeCell.Value = DateAdd("d", lngDate - 1, "1/1/1968")
End If
Next RangeCell
End Sub
It seems that Oracle may begin on 1/1/1968. I'm not a DB guy but I think that number sounds familiar in other reading I have done.
Here is an example routine that would convert the Oracle date to Excel date, if the above assumption of 1/1/1968 is true.
Sub OracleToExcelCSVDates()
Dim rng as Range 'range of cells containing dates'
Dim cl as Range
Dim strDate As String 'date received from Oracle'
Dim lngDate As Long
Dim newDate As Date 'Converted date'
Set rng = Range("J1:J1000") '< modify this for the number of rows you use in col J'
For each cl in rng 'Iterate over the rng you defined above.'
'Capture the date from Oracle'
strDate = cl.Value
If Not Trim(strDate) = vbNullString Then 'ignore blanks'
'convert to Long data type'
lngDate = CLng(strDate)
'Add the # of days (lngDate) to Oracles base date of 1/1/1968'
newDate = DateAdd("d", lngDate - 1, "1/1/1968")
'Overwrite the cell value with the new converted date:'
cl.Value = newDate
End If
End Sub
More info about Excel dates:
Excel stores serial dates as "a number representing the number of days since 1900-Jan-0, plus a fractional portion of a 24 hour day: ddddd.tttttt . This is called a serial date, or serial date-time."
http://www.cpearson.com/excel/datetime.

ASP.NET GridView fail to sort a Date passed as string

Hi I am building a site which has a gridview with AutoGenerateColumns = True, the issue that I am having is the Sort condition using a dataview does not work correctly for example. If I have the following records already displayed on the gridview:
Name Address Date (MM/DD/YYYY)
Julio XYZ Australia 12/25/2010
David 1234 New Zealand 12/26/2010
Erika 5555 Singapore 12/14/2011
If I do the sorting this way:
Dim dt As DataTable = Me.GetDataTable(Me.GetQuery(Sentence, params))
Dim dv As DataView = dt.DefaultView
dv.Sort = SortExpression & " " & SortDirection
gv.DataSource = dv
gv.DataBind()
The result in the grid is :
Name Address Date (MM/DD/YYYY)
Erika 5555 Singapore 12/14/2011
Julio XYZ Australia 12/25/2010
David 1234 New Zealand 12/26/2010
So the problem it seems to be the sort is only taking in consideration part of the date only the first five characters instead of the whole string.
The values for SortExpression is the ColumnName for Date which in the datasource is CallDate and the SorDirection Value is ASC
The Me.GetDataTable(Me.GetQuery(Sentence,paramas)) is just a way to populate the datatable with the records from the Database.
Another thing, sadly I cannot change the format of the Date because is a business requirement to be presented that way, also I am not allow to use third party controls because the budget of the project. :-(
Thanks for the any idea in advance.
First I want to confirm that whether your Date is DateTime type, if yes,
please try to sample as below, hope these will give you a hand.
Dim dt As DataTable = Me.GetDataTable(Me.GetQuery(Sentence, params))
dt.DefaultView.Sort = "Date ASC" ''Sort with Asc.
gv.DataSource = dt
gv.DataBind()

How to select Monthly and yearly Dates?

Using VB 6
Using two DTPicker in my project, I want to select monthly and yearly like MM/yyyy and yyyy
Now am Using Daily Date’s like 23/02/2009 (dd/MM/yyyy), I want to use like Monthly (MM/yyyy) and Yearly (yyyy)
My Code
Public Function DaysInMonth(dte As Date) As Integer
Dim d As Date
d = DateAdd("m", 1, dte)
d = DateAdd("d", -1, d)
DaysInMonth = Day(d)
End Function
Private Sub Form_Load()
Dim dteFrom As Date
Dim dteTo As Date
dteFrom = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & "01"), "yyyy-mm-dd")
dteTo = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & DaysInMonth(dteFrom)), "yyyy-mm-dd")
dtpFrom.Value = dteFrom
dtpTo.Value = dteTo
End Sub
Above code is working for daily dates. I want to use monthly and yearly dates also
Now I am selecting a date it showing complete value of the date like 03-02-2009, I want to show monthly and Yearly data’s
Expected Output.
Monthly Date
03/2009 to 04/2009 – It should take a value of 01/03/2009 to 30/04/2009
05/2009 to 05/2009 – It should take a value of 01/05/2009 to 31/05/2009
Yearly Date
2008 to 2008 – It should take a value of 01/01/2008 to 31/12/2008
2008 to 2009 – It should take a value of 01/01/2008 to 31/12/2009
How to select monthly and yearly?
Need VB 6 code Help
You can set the Format on the DTPicker to 3 (dtpCustom) and the CustomFormat to MM/yyyy . This will display month/year format in the text section, but you will still get the full calendar on drop down.
If you want to disable the calendar, you can set UpDown to True. Then you will get up/down buttons instead of the dropdown.
You need to make sure that the hidden value (day part) is correct.
EDIT:
OK, from your comment I understand that you are happy with the date picker, but you want to display the result in a special format?
Example:
Date selected is 20/8/2009 and stored in a date variable a.
Display as 2009:
MsgBox Format(a, "yyyy")
Display as 08/2009:
MsgBox Format(a, "mm/yyyy")
Display as August, 2009:
MsgBox Format(a, "mmmm, yyyy")
Display as Aug, 2009:
MsgBox Format(a, "mmm, yyyy")
Is this what you want?

Resources