I'm getting "August 22, 2015 10:55" in a querystring and I want to convert it to "2015-08-22 10:55".
I have this so far:
datum=request.querystring("tid")
response.write datum ----this writes out August 22, 2015 10:55
datum=Cstr(datum)
DateVar = datevalue(datum)
NewDateVar = year(DateVar) & "-" & month(DateVar) & "-" & day(DateVar)
NewTimeVar=timevalue(datum)
newdatum = NewDateVar & " " & NewTimeVar
But now I get a type missmatch error on DateVar = datevalue(datum).
If I use datum="August 22, 2015 10:55" to test with, then it works.
To spell it out:
>> s = "August 22, 2015 10:55"
>> d = CDate(s)
>> WScript.Echo TypeName(d), d
>>
Date 22.08.2015 10:55:00 <-- german locale!
Added:
To get the required format, you can use the strategy described here.
DateVar = datevalue("August 22, 2015 10:55")
NewDateVar = year(DateVar) & "-" & month(DateVar) & "-" & day(DateVar) & "-" & time(DateVar)
Classic ASP tends to use US date formats, come hell or high water. However, it's easy enough to format the date you display (or pass on to the database) in whatever way you wish.
The following will pad any single-digit values with a 0. If you don't need that, then just use the plain functions, without Right().
Dim datum, mm, dd, yyyy, hh, nn, fdatum
datum = Request.Querystring("tid")
If IsDate(datum) Then
datum = CDate(datum)
mm = Right(100 + Month(datum),2)
dd = Right(100 + Day(datum),2)
yyyy = Year(datum)
hh = Right(100 + Hour(datum),2)
nn = Right(100 + Minute(datum),2)
fdatum = yyyy & "-" & mm & "-" & dd & " " & hh & ":" & nn
Else
fdatum = datum '- or whatever fallback value you want
End If
Related
I could use some help performing a database correction, in regards to date and time of pictures were taken.
Essentially, the research we perform entails taking many pictures and entering the picture information into a database (we automated this with Microsoft Access). However, I performed a random check of our database and found that several dates and times of the photos were incorrect, and I am attempting to correct this via R as I was unable to correct it via Access.
What I need to do is to is write a script that reads these data, and compiles a list of the date taken information for all photos (there are several thousand). So far the best thing that I've found is
file.info(list.files(
"E:/Whatcom Creek Project/Data/Seal photos/Discovery/Catalog/Phoca vitulina",
recursive = T))
However this returns a list of NA NA for all information. Also, if I manually select one image to run file.info on, it doesn't return date taken (see the picture for the data I am attempting to retrieve)
If anyone has any suggestions I am all ears. Thanks in advance!!
-Ian
enter image description here
maybe still of any use?
i saw this message. I solved this a long time ago (2011) with a very basic VB6 code. The job is still working, but it is not applicable to all '.jpg files'. It depends with what camera the picture has been taken, but mostly pictures taken from a smartphone and classic camera's are returning the date the picture has been taken (not usable for whatsapp images or edited images).
The code is here below, and it is very basic code (but i hope it still can help or give idea's, and ... any new idea's are welcome too) :
'Reading of "Date Picture Taken" from .jpg file
'-----------------------------------------------
Debug.Print ">>>>>==== Start Read of .jpg-file ===== "; Date; " ===== "; Time; " ====<<<<<"
X = 0
DatePictureTaken = ""
TimePictureTaken = ""
FOUNDdatum = False
SWdatum = False
TELdatum = 0
Foto = FOLDER & "\" & tabFileName(FotoNr)
Open Foto For Binary Access Read As #1
'get startposition of the field "date picture taken"
Do
X = X + 1
Get #1, X, MyByte ': Debug.Print Chr(MyByte);
DoEvents
If Chr(MyByte) = ":" Then
'Debug.Print
SWdatum = True
Get #1, X + 3, MyByte
'Debug.Print "x+03="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+03="; Chr(MyByte)
Get #1, X + 9, MyByte
'Debug.Print "x+09="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+09="; Chr(MyByte)
Get #1, X + 12, MyByte
'Debug.Print "x+12="; Chr(MyByte)
If Chr(MyByte) <> ":" Then SWdatum = False 'Debug.Print "x+12="; Chr(MyByte)
'if a ':' is on the 3 locations (found above) then it is a date!
If SWdatum _
Then
TELdatum = TELdatum + 1
End If
'the 3e date is the date the picture has been taken
If TELdatum = 3 _
Then
FOUNDdatum = True
X = X - 4
Exit Do
End If
X = X + 12
End If
Loop Until EOF(1) 'Or X = 32765
If FOUNDdatum = False Then Close 1: End
BPdatum = X
EPdatum = X + 9
BPuur = X + 11
EPuur = X + 15
For X = BPdatum To EPdatum
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
DatePictureTaken = DatePictureTaken & Chr(MyByte)
End If
Next X
For X = BPuur To EPuur
Get #1, X, MyByte
'Debug.Print Chr(MyByte)
If Chr(MyByte) <> ":" _
Then
' DatePictureTaken = DatePictureTaken & "/"
'Else
TimePictureTaken = TimePictureTaken & Chr(MyByte)
End If
Next X
'Debug.Print "Date Picture Taken = "; DATUM
tbxDatum.Text = DatePictureTaken
tbxUur.Text = TimePictureTaken
Close 1
End Sub
I have read many post but nothing really helped.
My question looks similar but bit different.
I have to change EPOC time to system time format.
data type = datetime
value= 20160630165419.634204+060
desired output
data type = datetime
value= 30/06/2016 16:54:19
as the EPOC value has digits after dot and the datatype is datetime , which makes it difficult to divide it by 10 in a loop and get ingteral value.
Please suggest solution for given input format only.
You can use this function WMIDateStringToDate for converting your date :
WScript.echo WMIDateStringToDate("20160227235343.000000+060")
WScript.echo WMIDateStringToDate("20160630165419.634204+060")
'************************************************************
Function WMIDateStringToDate(Mydate)
WMIDateStringToDate = CDate(Mid(Mydate, 5, 2) & "/" & _
Mid(Mydate, 7, 2) & "/" & Left(Mydate, 4) _
& " " & Mid (Mydate, 9, 2) & ":" & _
Mid(Mydate, 11, 2) & ":" & Mid(Mydate,13, 2))
End Function
'************************************************************
Step 1: use DateSerial() and TimeSerial() on numbers (CInt()) extracted from your input (Mid()) to get a variant of subtype Date
Step 2: use SetLocale() and Replace() to format/stringify the Date
>> SetLocale "de-de"
>> sX = "20160630165419.634204+060"
>> dtD = DateSerial(CInt(Mid(sX, 1, 4)), CInt(Mid(sX, 5, 2)), CInt(Mid(sX, 7, 2)))
>> dtT = TimeSerial(CInt(Mid(sX, 9, 2)), CInt(Mid(sX, 11, 2)), CInt(Mid(sX, 13,2)))
>> dtX = dtD + dtT
>> WScript.Echo dtX, TypeName(dtX)
>> WScript.Echo Replace(dtX, ".", "/")
>>
30.06.2016 16:54:19 Date
30/06/2016 16:54:19
Danger, Will Robinson! Look at this test script:
Function WMIDateStringToDate(Mydate)
WMIDateStringToDate = CDate(Mid(Mydate, 5, 2) & "/" & _
Mid(Mydate, 7, 2) & "/" & Left(Mydate, 4) _
& " " & Mid (Mydate, 9, 2) & ":" & _
Mid(Mydate, 11, 2) & ":" & Mid(Mydate,13, 2))
End Function
'************************************************************
For Each sLocale In Split("de-de en-us")
SetLocale sLocale
For Each sDate In Split("20160227235343.000000+060 20160203235343.000000+060")
On Error Resume Next
dtX = WMIDateStringToDate(sDate)
If Err.Number Then dtX = Err.Description
On Error GoTo 0
WScript.Echo GetLocale(), sD, sDate, dtX
Next
Next
and its output:
cscript 38249865.vbs
1031 20160227235343.000000+060 27.02.2016 23:53:43
1031 20160203235343.000000+060 02.03.2016 23:53:43
1033 20160227235343.000000+060 27.02.2016 23:53:43
1033 20160203235343.000000+060 03.02.2016 23:53:43
to see the reason for:
The sample scripts are not supported under any Microsoft standard
support program or service. The sample scripts are provided AS IS
without warranty of any kind. Microsoft further disclaims all implied
warranties including, without limitation, any implied warranties of
merchantability or of fitness for a particular purpose. The entire
risk arising out of the use or performance of the sample scripts and
documentation remains with you. In no event shall Microsoft, its
authors, or anyone else involved in the creation, production, or
delivery of the scripts be liable for any damages whatsoever
(including, without limitation, damages for loss of business profits,
business interruption, loss of business information, or other
pecuniary loss) arising out of the use of or inability to use the
sample scripts or documentation, even if Microsoft has been advised of
the possibility of such damages.
(found here)
I am working on a calendar application and I want to display the date such as: mm/dd/yy. The reason for this is because on mobile devices some of my dates are getting recognized as phone numbers when it is in mm/dd/yyyy. I couldn't find a VBScript function to accomplish this so I tried it with the following code:
listyear = Year(strlistdate)
listyearabbr = Right(listyear, 2)
strlistdate = Replace(strlistdate, listyear, listyearabbr)
Where strlistdate is the initial date returned from the database. I then display the date using Response.write("<td>" &FormatDateTime(strlistdate,2)&"</td>")
This didn't work and I was wondering if someone could give me a few pointers on how to achieve this.
Thanks
I don't think that this is a good approach, because you'll end up returning the same date format for all locales, but you could do this:
response.write(Month(strlistdate) & "/" & Day(strlistdate) & "/" & Right(Year(strlistdate),2))
Anytime you use FormatDateTime, it will create a year based on the definition stored on the server. If the server can be set to mm/dd/yy, then you can get the output you want without doing any of the above.
Also, look into the format function. You should be able to do this:
response.write(Format(strlistdate, "m/dd/y")
You could try this idea. I haven't used date formatting for years. Instead I construct the date field like so...
strDay = Day(Date)
strMonth = Month(Date)
strYear = Year(Date)
strHours = Hour(Now)
strMins = Minute(Now)
strSecs = Second(Now())
if len(strMonth) = 1 then
strMonth = "0" & strMonth
end if
if len(strDay) = 1 then
strDay = "0" & strDay
end if
if len(strHours) = 1 then
strHours = "0" & strHours
end if
if len(strMins) = 1 then
strMins = "0" & strMins
end if
if len(strSecs) = 1 then
strSecs = "0" & strSecs
end if
strDateAdded = strYear & "-" & strMonth & "-" & strDay
strDateAddedTime = strDateAdded & " " & strHours & ":" & strMins
Using this method you have complete control over the order and even when running your web app in different time zones, you still maintain DD/MM format... or whatever order you want such as MM-DD-YY (by reordering and trimming the year). Personally I prefer YYYY-MM-DD because sorting by ASC and DESC is a lot easier to work with, ie: easier to read because all rows will have the same number of characters like:
2013-04-01 03:15
2013-04-09 10:15
2013-04-22 07:15
2013-04-23 10:15
2013-04-23 10:60
2013-10-25 12:01
2013-10-25 12:59
Instead of:
2013-4-1 3:15
2013-4-9 10:15
2013-4-22 7:15
2013-4-23 10:15
2013-4-23 10:60
2013-10-25 12:1
2013-1-25 12:59
If I run following code in VBScript all works as expected, if i run it in ASP (IIS 7) the I get this wrong result. Does anyone know why?
mumber = "027609366"
WScript.Echo Left(number, 2) & " " & _
Mid(number, 3, 2) & " " & _
Mid(number, 5, 2) & " " & _
Right(number, 3)
' vbs => 03 76 09 366 (right)
' asp => 03 76 09 66 (wrong)
I now use the following which works:
Left(number, 2) & " " & _
Mid(number, 3, 2) & " " & _
Mid(number, 5, 2) & " " & _
Mid(number, 7)
But i wonder why this happens.
ASP code is written using VBScript, so the results can't be different, as they are technically the same thing.
Is there an extra space on the end of one of your numbers somewhere, that could be causing the number to be displayed incorrectly?
Here is some math code that adds A to B:
Sub math()
A = 23
B = 2
ABSumTotal = A + B
strMsg = "The answer is " & "$" & ABSumTotal & "."
MsgBox strMsg
End Sub
But how can I calculate a square root of ABSumTotal?
Is it possible in PowerPoint VBA?
Use: Sqr()
strMsg = "The answer is " & "$" & Sqr(ABSumTotal) & "."
Have you tried the function Sqr?
See:
http://msdn.microsoft.com/en-us/library/h2h9y284%28VS.85%29.aspx
You can use use ^ to compute X^(1/2)
Edit: added parenthesis