I want to get timestamp of a different country in VBA. Is there any direct function or way to get it? For example, I am in India working for Mexico and I want to do certain task based on Mexican Time. I was able to get it by splitting the timestamp and manipulating it but could not consider daylight saving in it. Is there any simple solution than writing a big user-defined function?
Know your time zone offset & your client's time zone offset, then use that to calculate the difference
Dim IndiaTZ as single
Dim MexicoTZ as single
Dim MyTime as date
Dim UTC as date
Dim MexicoTime as date
IndiaTZ = 5.5
MexicoTZ = -4
'note this assumes that they're in Eastern time,
'Mexico also covers Central, Mountain & Pacific at -5, -6 & -7.
'You'll need to figure out which one you need.
MyTime = Now
'need to invert the offset to get from India to UTC
UTC = datediff("h", mytime, IndiaTZ * -1)
'need to invert the offset to get from UTC to Mexico
MexicoTime = Datediff("h", UTC, MexicoTZ * -1)
Related
I have a Java api which gets the data from oracle database which is in ET timezone. I want to query that table using sysdate on 2 columns but the sysdate should be picked as current BST date value not as ET date value.
select * from customers where sysdate between mem_registered_date and mem_deregistered_date;
How this can be done? please help
The simplest way to convert between time zones is to use a data type that understands time zones, a TIMESTAMP. Then when you've converted to the time zone you want then CAST it back to a DATE data type:
SELECT *
FROM customers
WHERE CAST( SYSTIMESTAMP AT TIME ZONE 'Europe/London' AS DATE )
BETWEEN mem_registered_date AND mem_deregistered_date;
I'm assuming that you want the current time in the United Kingdom (BST in summer and GMT in winter), if you want the time zone UTC+1 then use:
CAST( SYSTIMESTAMP AT TIME ZONE '+01:00' AS DATE )
If querying a column with a date-only value, without any time-of-day nor any time zone, that is, a column of a type akin to the SQL-standard DATE type, then use Java class LocalDate.
Generally best to use half-open definition of a span of time, where the beginning is inclusive while the ending is exclusive. This allows spans to nearly abut one another without gaps or overlap. So never use the SQL command BETWEEN for date-time ranges, as it is fully-closed (both beginning and ending are inclusive).
Get today’s date as seen in the wall-clock time used by the people of a particular region (a time zone).
BST is not a real time zone. For British time, use Europe/London.
ZoneId z = ZoneId.of( "Europe/London" ) ;
LocalDate today = LocalDate.now( z ) ;
The SQL will look something like this:
SELECT *
FROM event_
WHERE ? >= start_
AND ? < end_
;
Fill in the placeholders.
myPreparedStatement.setObject( 1 , today ) ;
myPreparedStatement.setObject( 2 , today ) ;
Load the date values from database into Java.
LocalDate start = myResultSet.getObject( … , LocalDate.class ) ;
TIMESTAMP WITHOUT TIME ZONE
The misnamed DATE in the Oracle database actually represents a date with time-of-date without the context of a time zone or offset-from-UTC. As such, this type cannot represent a moment, a specific point on the timeline. It the value is noon on the 23rd of January next year, we cannot know if that is noon in Tokyo, Toulouse, or Toledo — all different moments several hours apart. This DATE type is akin to the SQL-standard type TIMESTAMP WITHOUT TIME ZONE.
So for this data type, your question asking about time zones makes no sense. Apple and oranges. Involving time zones means you are tracking moments, specific points on the timeline. But the Oracle DATE cannot represent moments as discussed above.
To track moments, your should be using a column of a type akin to the SQL-standard TIMESTAMP WITH TIME ZONE.
I have a function that returns the online date and time but for some reason the minutes are not working. When I add a value to the minutes it always stays the same and won't move forward.
Public Function OnlineTimeNow() As DateTime
' --- create instance of UDP
Dim objSck As System.Net.Sockets.UdpClient
Dim ipAny As System.Net.IPEndPoint = New System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)
objSck = New System.Net.Sockets.UdpClient(ipAny)
' --- send UDP
Dim sdat As Byte() = New Byte(47) {}
sdat(0) = &HB
objSck.Send(sdat, sdat.GetLength(0), "time.windows.com", 123)
' --- receive UDP
Dim rdat As Byte() = objSck.Receive(ipAny)
' elapsed time (date and time) from 1900/01/01 ---
Dim elapsedTotalSec As Long ' elapsed seconds from 1900/01/01 ---
Dim Days As Long ' days --- 日
Dim HH As Long ' hours --- 時
Dim MM As Long ' minutes --- 分
Dim SS As Long ' seconds --- 秒
' --- elapsed seconds from 1900/01/01 ---
elapsedTotalSec = CLng(
rdat(40) * Math.Pow(2, (8 * 3)) +
rdat(41) * Math.Pow(2, (8 * 2)) +
rdat(42) * Math.Pow(2, (8 * 1)) +
rdat(43))
' ---
Days = elapsedTotalSec \ (24 * 60 * 60) ' days
SS = elapsedTotalSec Mod (24 * 60 * 60) ' mod seconds
HH = SS \ (60 * 60)
SS = SS Mod (60 * 60)
MM = MM \ (60 * 60)
SS = SS Mod 60
' --- convert to DateTime type
'Dim dtTime As DateTime = "1900/01/01"
Dim dtTime As DateTime
'dtTime = dtTime.AddDays(Days)
dtTime = dtTime.AddHours(HH)
dtTime = dtTime.AddMinutes(MM)
dtTime = dtTime.AddSeconds(SS)
' --- change Greenwich Mean Time to local time (my sample is Japanese Time)
dtTime = dtTime.AddHours(8) ' <<-- *** please modify (n) according to your location ***
' ---
Return dtTime
End Function
If you want to get the GTM time, you can do it simply with :
Dim dtTime As DateTime
dtTime = DateTime.UtcNow
This is an exemple on how to convert Utc time to another time zone :
Sub Main()
Dim DT As DateTime = DateTime.UtcNow
Dim DTSEAsia As DateTime
Dim Tz As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time")
DTSEAsia = TimeZoneInfo.ConvertTimeFromUtc(DT, Tz)
End Sub
And this are the value possible for a TimeZoneInfo
Dateline Standard Time
UTC-11
Samoa tandard Time
Hawaiian Standard Time
Alaskan Standard Time
Pacific Standard Time (Mexico)
Pacific Standard Time
US Mountain Standard Time
Mountain Standard Time (Mexico)
Mountain Standard Time
Central America Standard Time
Central Standard Time
Central Standard Time (Mexico)
Canada Central Standard Time
SA Pacific Standard Time
Eastern Standard Time
US Eastern Standard Time
Venezuela Standard Time
Paraguay Standard Time
Atlantic Standard Time
Central Brazilian Standard Time
SA Western Standard Time
Pacific SA Standard Time
Newfoundland Standard Time
E.South America Standard Time
Argentina Standard Time
SA Eastern Standard Time
Greenland Standard Time
Montevideo Standard Time
UTC-2
Mid-Atlantic Standard Time
Azores Standard Time
Cape Verde Standard Time
Morocco Standard Time
UTC
GMT Standard Time
Greenwich Standard Time
W.Europe Standard Time
Central Europe Standard Time
Romance Standard Time
Central European Standard Time
W.Central Africa Standard Time
Namibia Standard Time
Jordan Standard Time
GTB Standard Time
Middle East Standard Time
Egypt Standard Time
Syria Standard Time
South Africa Standard Time
FLE Standard Time
Israel Standard Time
E.Europe Standard Time
Arabic Standard Time
Arab Standard Time
Russian Standard Time
E.Africa Standard Time
Iran Standard Time
Arabian Standard Time
Azerbaijan Standard Time
Mauritius Standard Time
Georgian Standard Time
Caucasus Standard Time
Afghanistan Standard Time
Ekaterinburg Standard Time
Pakistan Standard Time
West Asia Standard Time
India Standard Time
Sri Lanka Standard Time
Nepal Standard Time
Central Asia Standard Time
Bangladesh Standard Time
N.Central Asia Standard Time
Myanmar Standard Time
SE Asia Standard Time
North Asia Standard Time
China Standard Time
North Asia East Standard Time
Singapore Standard Time
W.Australia Standard Time
Taipei Standard Time
Ulaanbaatar Standard Time
Tokyo Standard Time
Korea Standard Time
Yakutsk Standard Time
Cen.Australia Standard Time
AUS Central Standard Time
E.Australia Standard Time
AUS Eastern Standard Time
West Pacific Standard Time
Tasmania Standard Time
Vladivostok Standard Time
Central Pacific Standard Time
New Zealand Standard Time
UTC+12
Fiji Standard Time
Kamchatka Standard Time
Tonga Standard Time
Just To Post a Simple Method for the Next User "Online Date and Time VB.NET"
Private Sub OnlineDateAndTime()
Dim client As WebClient = New WebClient()
'Download The TextFile From Web.
'Refer To "https://worldtimeapi.org/" about the link below
Dim DateAndTimeFromWeb = DateTimeOffset.Parse(client.DownloadString("https://worldtimeapi.org/api/timezone/Asia/Manila.txt").Split(ChrW(10)).Skip(2).First().Substring(10))
Dim TimeNow As DateTime
Dim DateNow As DateTime
'Get Only Time
TimeNow = DateAndTimeFromWeb.ToString
TimeNow = TimeOfDay.ToString("h:mm:ss tt")
'Get Only Date
DateNow = DateAndTimeFromWeb.ToString
DateNow = DateTime.Now.ToString("dd/MM/yyyy")
'Show Results in Textbox or Label or Any
TextBox1.Text = DateNow
TextBox2.Text = TimeNow
End Sub
Credits to #Jimi - Thanks ^_^
I writing application using vb .net.
In my application I got text box displaying current date.
As usually after midnight date is changing.
There is any chance to set delay that date will change after 02:00 am next day ?
For example:
Today is 09/07/17 and I need that after midnight textbox will still show this date. But after 02:00 am ( 10/07/117 ) date will change for 10/07/17.
My current code:
Private Sub HOMESCREEN_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SMARTSCREEN.MdiParent = Me
SMARTSCREEN.StartPosition = FormStartPosition.CenterScreen
SMARTSCREEN.Show()
SMARTSCREEN.datee.Text = Date.Today()
SMARTSCREEN.NOWEEK.Text = (DatePart("WW", Now))
Thanks,
The big (actually huge) question is, in what time zone is that 2:00 am you're talking about? You can easily achieve that by simply changing the time zone.
Say your time zone is US Eastern Time -5, then setting the time zone in your code to US Mountain Time -7 will effectively give you the result you want.
EDIT: This is trivial, but since you mentioned that you're in UK, then I assume that your time zone is London 0, so set to Coordinated Universal Time -2 to achieve what you want.
Alternatively, it can be simpler in your code to just subtract two hours:
SMARTSCREEN.datee.Text = DateTime.Now.AddHours(-2).ToString("d")
I would like to check if any specified timezone (other than my local time zone) is in DST or not.
To check if the local time zone is currently DST I am using:
Dim today_date As Date = Now.Date
Msgbox(today_date.IsDaylightSavingTime())
I would like to check if other time zones ("A.U.S. Eastern Standard Time" and "New Zealand Standard Time") are in DST according to today's date.
So what I have so far:
Dim AusZoneId As String = "A.U.S. Eastern Standard Time"
Dim AusZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(AusZoneId)
MsgBox(AusZone.SupportsDaylightSavingTime)
'Established True or False if TZ supported DST
What I want to do is feed in a date (eg today) and see if this date according to AUS Eastern Standard time is in DST.
You shouldn't do it for a date, as that can be ambiguous (the start of the day in standard time and the end of the day in daylight time, or vice versa) but instead ask whether a specific point in time is in daylight time:
Dim zoneId As String = "AUS Eastern Standard Time";
Dim zone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(zoneId)
Dim dst As Boolean = zone.IsDaylightSavingTime(DateTime.UtcNow)
(Or use some other point in time, of course.) I'd strongly encourage you to pass in a DateTime with a Kind of Utc.
I'm having a bit of trouble with the mongodb c# driver, in that it seems to be converting all my dates to a UTC form.
I have
Dim cDate as Date
Dim year as integer = 2012
Dim month as integer = 12
Dim day as integer = 21
cDate = New Date(year, month, day)
However putting it into a mongodb database via the C# driver seems to convert it to UTC so all of a sudden its a different day now because its now 11:00 PM 20th December 2012. Not exactly what I wanted!
Is there a way I can create the New Date(year, month, date such that its an UTC mode to begin with? So if i did cDate.utcNow I would get the same thing as cDate, in essence cDate.utcNow = cDate?
I have tried all sorts of stuff with the driver only to run into a brick wall such as using the DateTimeSerializationOptions.Defaults to no avail nothing happens!
To create your date as a UTC date, just specify the Kind parameter in the constructor along with the hours, minutes, and seconds:
cDate = New Date(year, month, day, 0, 0, 0, DateTimeKind.Utc)