Hi all,
Probably a stupid question, but I'm not finding any way to do it now... I see that VBScript can take a date string and read from there, but the manual says, it's under condition, that this string presents the system date/time format settings, and I don't know which format settings will be on that computer.
What can I do?
Thank you,
Olga.
How to convert month, day, year, hour, min. to date (VBS)?
Moderators: JRL, Dorian (MJT support)
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Can you clarify what you are trying to do? I don't really understand what you are saying. VBScript has a number of date formatting functions which let you format the date anyway you want to, regardless of system settings.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thank you, Marcus!!
I get as an input from the user day, month, year, hour, minutes and from this I should form a date that I can give then to functions like Add in Macro Scheduler or DateAdd in VBS.
I just remembered there was in JScript a function forming a date from separate numbers representing day, month, etc. - but I don't seem to find it in VBS. I see only CDate, which takes a date string, DateValue - the same, etc., but how do I form a date in the system format if I don't' know it?
Which functions did you have in mind that could do this?
Thank you!
Olga.
I get as an input from the user day, month, year, hour, minutes and from this I should form a date that I can give then to functions like Add in Macro Scheduler or DateAdd in VBS.
I just remembered there was in JScript a function forming a date from separate numbers representing day, month, etc. - but I don't seem to find it in VBS. I see only CDate, which takes a date string, DateValue - the same, etc., but how do I form a date in the system format if I don't' know it?
Which functions did you have in mind that could do this?
Thank you!
Olga.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Use DateSerial. DateSerial takes the component parts and returns a VBScript date value:
http://msdn.microsoft.com/library/en-us ... 027662.asp
E.g:
DateDiff is also useful for determining the number of days between dates. Don't forget you can also subtract days from dates with DateAdd by specifying a negative number.
http://msdn.microsoft.com/library/en-us ... 027662.asp
E.g:
Code: Select all
VBSTART
VBEND
Day>dd
Month>mm
Year>yyyy
VBEval>DateAdd("d",1,DateSerial(%yyyy%,%mm%,%dd%)),tomorrow
VBEval>Year("%tomorrow%"),yyyy
VBEval>Month("%tomorrow%"),mm
VBEval>Day("%tomorrow%"),dd
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thank you!!! Seems to be exactly what I needed!
I thought how I can calculate the date together with time, so I wrote it like this:
Thank you very much!
Olga.
I thought how I can calculate the date together with time, so I wrote it like this:
Code: Select all
Function ReturnDate(intYears, intMonth, intDays, intHours, intMinutes)
Dim MyTime
MyTime = DateSerial(intYears, intMonth, intDays)
MyTime = DateAdd("h", intHours, MyTime)
MyTime = DateAdd("n", intMinutes, MyTime)
ReturnDate = MyTime
End Function
'now the returned can be given to DateAdd, DatePart, DateDiff etc. or printed out like this:
MsgBox Left(WeekDayName(Weekday(MyTime)),3) & ", " & Day(MyTime) & " " & MonthName(Month(MyTime),True) & " " & Year(MyTime) & " " & FormatDateTime(MyTime,vbShortTime)
Olga.